<template>
	<div v-loading="loading" class="app-main-content-box">
		<!-- 头部 -->
		<div class="app-main-top-box">
			<app-main-title :title="(mode === 'add' ? `添加券：` : '编辑券：') + couponTypeOptions[form.couponType]" />
			<el-button size="medium" round @click="back">返回</el-button>
		</div>

		<!-- 步骤条 start -->
		<div class="step-container">
			<el-steps :active="step">
				<el-step title="基础信息" description="配置卡券的基础信息" />
				<el-step title="发放和核销" description="投放和核销的规则" />
				<el-step title="样式主题" description="管理顾客端效果" />
				<el-step title="确认创建" description="检查并完成创建" />
			</el-steps>
		</div>
		<!-- 步骤条 end -->

		<!-- 表单 start -->
		<el-form ref="form" :model="form" :rules="rules" label-suffix="：" label-width="170px" size="small">
			<!-- step 0 开始 -->
			<div v-show="step === 0">
				<!-- 归属商户号 -->
				<!--        <div v-if="['cash_wx_pay','cash_wx_busi','discount_wx_busi'].includes(form.couponType)">-->
				<!--          <div>-->
				<!--            <el-form-item label="归属商户号" prop="wxPayMchid">-->
				<!--              <el-input-->
				<!--                v-model.trim="form.wxPayMchid"-->
				<!--                placeholder="请输入微信支付的商户号"-->
				<!--                class="w-400"-->
				<!--              />-->
				<!--            </el-form-item>-->
				<!--          </div>-->
				<!--        </div>-->

				<!--归属商户号-->
				<div v-if="['cash_wx_pay', 'cash_wx_busi', 'discount_wx_busi'].includes(form.couponType)">
					<div>
						<el-form-item label="归属商户号" prop="belongMchid"><el-input v-model.trim="form.belongMchid" placeholder="请输入" class="w-400" /></el-form-item>
					</div>
				</div>

				<!-- 券名 -->
				<div>
					<el-form-item label="券名称" prop="couponName"><el-input v-model="form.couponName" maxlength="40" placeholder="请输入" class="w-400" /></el-form-item>
				</div>

				<!-- 代金券 -->
				<div v-if="couponTypeGroup.cash.includes(form.couponType)">
					<div>
						<!-- 券面额 -->
						<el-form-item label="券面额" prop="denomination" class="is-required">
							<el-input v-model.trim="form.denomination" maxlength="8" placeholder="请输入" class="w-170">
								<template slot="append">
									元
								</template>
							</el-input>
						</el-form-item>
					</div>
				</div>

				<!-- 券门槛 -->
				<div v-if="['cash', 'cash_wx_busi'].includes(form.couponType)">
					<el-form-item label="门槛" class="is-required">
						<span>订单消费满&nbsp;</span>
						<el-form-item prop="transactionMinimum" style="display:inline-block">
							<el-input v-model.trim="form.transactionMinimum" maxlength="8" placeholder="请输入" class="w-170">
								<template slot="append">
									元
								</template>
							</el-input>
						</el-form-item>
						<span>&nbsp;可用，最多支持叠加使用&nbsp;</span>
						<el-form-item prop="maxUseNum" style="display:inline-block">
							<el-input v-model.trim="form.maxUseNum" placeholder="请输入" maxlength="2" class="w-170">
								<template slot="append">
									张
								</template>
							</el-input>
						</el-form-item>
						<div class="tips-text">
							叠加使用是指顾客消费每消费满一个【最低可用金额】的区间则可以使用一张代金券
							<br />
							比如100减30的优惠券， 消费200元可用2张， 但是消费180只可以使用一张
						</div>
					</el-form-item>
				</div>

				<!-- 券门槛 -->
				<div v-if="['cash_wx_pay'].includes(form.couponType)">
					<div>
						<el-form-item label="门槛" prop="transactionMinimum">
							<el-input v-model.trim="form.transactionMinimum" maxlength="8" placeholder="请输入" class="w-170">
								<template slot="append">
									元
								</template>
							</el-input>
						</el-form-item>
					</div>
				</div>

				<!-- 折扣券 -->
				<div v-if="couponTypeGroup.discount.includes(form.couponType)">
					<div>
						<el-form-item label="折扣" prop="discountPercent">
							<el-input v-model.trim="form.discountPercent" maxlength="3" placeholder="请输入" class="w-170">
								<template slot="append">
									折
								</template>
							</el-input>
						</el-form-item>
						<el-form-item label="门槛" prop="transactionMinimum">
							<span>订单消费满&nbsp;</span>
							<el-input v-model.trim="form.transactionMinimum" maxlength="8" placeholder="请输入" class="w-170">
								<template slot="append">
									元
								</template>
							</el-input>
							<span>可用</span>
							<div class="tips-text">如果需要限制券的起用金额请输入，留空则代表不限制</div>
						</el-form-item>
						<el-form-item label="优惠上限" prop="discountMaximum">
							<span>订单最高优惠&nbsp;</span>
							<el-input v-model.trim="form.discountMaximum" maxlength="8" placeholder="请输入" class="w-170">
								<template slot="append">
									元
								</template>
							</el-input>
							<div class="tips-text">如果需要限制券的最大可优惠金额请输入，留空则代表不限制</div>
						</el-form-item>
					</div>
				</div>

				<!-- 兑换券 -->
				<div v-if="couponTypeGroup.exchange.includes(form.couponType)">
					<el-form-item label="兑换内容" prop="exchangeThings">
						<el-input v-model="form.exchangeThings" placeholder="请输入" maxlength="30" show-word-limit class="w-400" />
					</el-form-item>
					<el-form-item label="价值" prop="denomination">
						<span>兑换商品共价值&nbsp;</span>
						<el-input v-model.trim="form.denomination" maxlength="10" placeholder="请输入" class="w-170">
							<template slot="append">
								元
							</template>
						</el-input>
						<div class="tips-text">将会作为面值显示给用户，但是该券只支持到店核销，不支持支付时使用</div>
					</el-form-item>
				</div>

				<!-- 可用时间 -->
				<el-form-item label="可用时间" class="is-required">
					<el-form-item prop="date">
						<el-date-picker
							v-model="form.date"
							:picker-options="datePickerOptions"
							:default-time="['00:00:00', '23:59:59']"
							type="datetimerange"
							range-separator="~"
							start-placeholder="开始日期"
							end-placeholder="结束日期"
							value-format="yyyy-MM-dd HH:mm:ss"
						/>
						<span v-if="form.couponType === 'cash_wx_pay'">日期跨度不能大于90天</span>
					</el-form-item>

					<!-- 时间类型 -->
					<el-form-item>
						<el-select v-model="form.availableTime.timeType" placeholder="请选择" style="width:350px">
							<template v-for="item in useRuleOptions">
								<el-option v-if="item.value !== 3 && item.value !== 4 && item.value !== 1" :key="item.value" :label="item.label" :value="item.value" />
								<el-option
									v-if="
										(item.value === 3 && ['cash', 'discount', 'exchange'].includes(form.couponType)) ||
											((item.value === 1 || item.value === 4) && form.couponType !== 'cash_wx_pay')
									"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								/>
							</template>
						</el-select>
					</el-form-item>

					<!-- 时间类型一 -->
					<el-collapse-transition>
						<div v-if="form.availableTime.timeType === 1" class="nest-card-box">
							<el-card>
								<div>
									<span>生效后&nbsp;</span>
									<el-form-item prop="availableTime.days" style="display:inline-block">
										<el-input v-model="form.availableTime.days" placeholder="请输入" class="w-170">
											<template slot="append">
												天
											</template>
										</el-input>
									</el-form-item>
									<span>&nbsp;内可使用</span>
								</div>
								<div class="tips-text">
									用户在活动有效期开始前领取券，则从活动有效期第一天开始计算天数
									<br />
									用户在活动有效期内领取券，则从领取当天开始计算天数
									<br />
									无论用户何时领取券，券在活动有效期结束后均不可用
								</div>
							</el-card>
						</div>
					</el-collapse-transition>

					<!-- 时间类型 234 -->
					<el-collapse-transition>
						<div v-if="[2, 3, 4].includes(form.availableTime.timeType)" class="nest-card-box">
							<el-card>
								<el-form-item v-if="form.availableTime.timeType === 2" prop="availableTime.availablePeriodWeek">
									<el-checkbox-group v-model="form.availableTime.availablePeriodWeek">
										<el-checkbox-button v-for="(weekItem, weekIndex) in weekOptions" :key="'week-' + weekIndex" :label="String(weekItem.value)">
											{{ weekItem.label }}
										</el-checkbox-button>
									</el-checkbox-group>
								</el-form-item>
								<div v-if="form.availableTime.timeType === 3">
									<div class="tips-text">选择日期后，每一个自然月的当天都可使用</div>
									<el-form-item prop="availableTime.availablePeriodDay">
										<el-checkbox-group v-model="form.availableTime.availablePeriodDay" class="day-box">
											<el-checkbox-button v-for="(dayItem, dayIndex) in 31" :key="'day-' + dayIndex" :label="String(dayItem)">
												{{ dayItem }}
											</el-checkbox-button>
										</el-checkbox-group>
									</el-form-item>
								</div>
								<div v-if="form.availableTime.timeType === 4">
									<div class="tips-text">
										可在有效期内任意选择时间天数，以及可用时段。
										<br />
										因当前系统支持问题，如选择不规则时间，卡包内当前仅会展示有效期，建议
										<br />
										将具体可用日期以及时间段填写在券使用说明内。
										<br />
									</div>

									<el-form-item prop="availableTime.availableDateList">
										<div v-for="(item, index) in form.availableTime.availableDateList" :key="'date' + index" style="margin-top:18px">
											<el-date-picker
												v-model="form.availableTime.availableDateList[index].date"
												type="daterange"
												range-separator="~"
												start-placeholder="开始日期"
												end-placeholder="结束日期"
												value-format="yyyy-MM-dd HH:mm:ss"
												format="yyyy-MM-dd HH:mm:ss"
												size="small"
											/>
											<el-button
												v-if="form.availableTime.availableDateList.length > 1"
												type="text"
												icon="el-icon-delete"
												class="app-text-color-danger"
												@click="delAvailableDateList(index)"
											>
												删除
											</el-button>
											<el-button
												v-if="form.availableTime.availableDateList.length === index + 1 && form.availableTime.availableDateList.length < 3"
												type="text"
												icon="el-icon-plus"
												class="app-text-color-primary"
												@click="addAvailableDateList"
											>
												添加
											</el-button>
										</div>
									</el-form-item>
								</div>
								<el-form-item prop="availableTime.availableTimeList">
									<div v-for="(item, index) in form.availableTime.availableTimeList" :key="'time' + index" style="margin-top:18px">
										<el-time-picker
											v-model="form.availableTime.availableTimeList[index].time"
											is-range
											value-format="HH:mm"
											format="HH:mm"
											range-separator="~"
											start-placeholder="开始时间"
											end-placeholder="结束时间"
											placeholder="选择时间范围"
										/>
										<el-button
											v-if="form.availableTime.availableTimeList.length > 1"
											type="text"
											icon="el-icon-delete"
											class="app-text-color-danger"
											@click="delAvailableTimeList(index)"
										>
											删除
										</el-button>
										<el-button
											v-if="form.availableTime.availableTimeList.length === index + 1 && form.availableTime.availableTimeList.length < 3"
											type="text"
											icon="el-icon-plus"
											class="app-text-color-primary"
											@click="addAvailableTimeList"
										>
											添加
										</el-button>
									</div>
								</el-form-item>
								<div class="tips-text">请按照24小时制输入可用时段，最多设置3个时段</div>
							</el-card>
						</div>
					</el-collapse-transition>
				</el-form-item>

				<!-- 生效时间 -->
				<!--v-if="form.availableTime.timeType===1&&['cash','discount','exchange','cash_wx_busi','discount_wx_busi'].includes(form.couponType)"-->
				<div>
					<el-form-item label="生效时间" class="is-required">
						<el-select v-model="form.secondDayAvailable" placeholder="请选择" class="w-400">
							<el-option :value="false" label="领取后立即生效" />
							<el-option :value="true" label="领取后第二天生效" />
						</el-select>
					</el-form-item>
				</div>

				<!-- 券说明 -->
				<el-form-item :class="{ 'is-required': ['cash_wx_busi', 'discount_wx_busi'].includes(form.couponType) }" label="使用说明" prop="description">
					<el-input
						v-model="form.description"
						:autosize="{ minRows: 2, maxRows: 10 }"
						type="textarea"
						maxlength="1024"
						show-word-limit
						placeholder="请输入"
						class="nest-card-box"
						style="margin-left:0"
					/>
				</el-form-item>
			</div>
			<!-- step 0 end -->

			<!-- step 1 start -->
			<div v-show="step === 1">
				<el-divider content-position="left">投放规则</el-divider>
				<div v-if="['cash', 'discount', 'exchange'].includes(form.couponType)">
					<!-- 发放预算 -->
					<el-form-item label="发放预算">
						<el-form-item prop="maxCoupons">
							<el-checkbox v-model="form.maxCouponsChecked">设置有效期内可发放总上限为&nbsp;</el-checkbox>
							<el-input v-model="form.maxCoupons" :disabled="!form.maxCouponsChecked" placeholder="请输入" maxlength="8" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
							<span>&nbsp;5 ≤ 次数 ≤ 10000000</span>
						</el-form-item>
						<el-form-item prop="maxCouponsByDay">
							<el-checkbox v-model="form.maxCouponsByDayChecked">设置一个自然日可发放上限为&nbsp;</el-checkbox>
							<el-input v-model="form.maxCouponsByDay" :disabled="!form.maxCouponsByDayChecked" placeholder="请输入" maxlength="8" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
							<span>&nbsp;5 ≤ 次数 ≤ 10000000</span>
						</el-form-item>
					</el-form-item>

					<!-- 用户类型 -->
					<el-form-item label="用户类型" class="is-required">
						<el-radio-group v-model="form.userGroup">
							<el-radio :label="1">所有人</el-radio>
							<el-radio :label="2">仅会员</el-radio>
							<el-radio :label="3">指定会员类型</el-radio>
						</el-radio-group>
						<el-collapse-transition>
							<div v-if="form.userGroup === 3" class="nest-card-box">
								<el-card :body-style="{ padding: '20px 20px 0 20px' }">
									<el-form-item prop="category">
										<el-checkbox-group v-model="form.category">
											<el-checkbox v-for="item in categoryList" :key="item.id" :label="String(item.id)">
												{{ item.status ? item.categoryName : item.categoryName + '(已停用)' }}
											</el-checkbox>
										</el-checkbox-group>
									</el-form-item>
								</el-card>
							</div>
						</el-collapse-transition>
					</el-form-item>

					<!-- 用户限制 -->
					<el-form-item label="用户限制">
						<el-form-item prop="maxUserDay">
							<el-checkbox v-model="form.maxUserDayChecked">设置一个自然日单用户可领取&nbsp;</el-checkbox>
							<el-input v-model="form.maxUserDay" :disabled="!form.maxUserDayChecked" placeholder="请输入" maxlength="10" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
						</el-form-item>
						<el-form-item prop="maxUserWeek">
							<el-checkbox v-model="form.maxUserWeekChecked">设置一个自然周单用户可领取&nbsp;</el-checkbox>
							<el-input v-model="form.maxUserWeek" :disabled="!form.maxUserWeekChecked" placeholder="请输入" maxlength="10" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
						</el-form-item>
						<el-form-item prop="maxUserMonth">
							<el-checkbox v-model="form.maxUserMonthChecked">设置一个自然月单用户可领取&nbsp;</el-checkbox>
							<el-input v-model="form.maxUserMonth" :disabled="!form.maxUserMonthChecked" placeholder="请输入" maxlength="10" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
						</el-form-item>
						<el-form-item prop="maxUserAll">
							<el-checkbox v-model="form.maxUserAllChecked">设置有效期内单个用户可领取&nbsp;</el-checkbox>
							<el-input v-model="form.maxUserAll" :disabled="!form.maxUserAllChecked" placeholder="请输入" maxlength="10" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
						</el-form-item>
					</el-form-item>
				</div>

				<!-- 商家券配置 -->
				<div v-if="['cash_wx_busi', 'discount_wx_busi'].includes(form.couponType)">
					<!-- 预算 -->
					<el-form-item label="发放预算" class="is-required">
						<el-form-item prop="maxCoupons">
							<span>批次总预算次数：&#12288;</span>
							<el-input v-model="form.maxCoupons" placeholder="请输入" maxlength="8" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
							<span>&nbsp;5 ≤ 次数 ≤ 10000000</span>
						</el-form-item>
						<!--            <div v-if="['cash_wx_busi'].includes(form.couponType)">-->
						<!--              <div>-->
						<!--                <el-form-item prop="maxAmount">-->
						<!--                  <span>批次总预算金额：&#12288;</span>-->
						<!--                  <span v-if="form.maxAmount">{{ form.maxAmount }} 元（0.01 ≤ 金额 ≤ 1000000000）</span>-->
						<!--                  <span v-else>输入总预算次数，券面额自动计算（总预算次数 x 券面额）</span>-->
						<!--                </el-form-item>-->
						<!--              </div>-->
						<!--            </div>-->
						<el-form-item prop="maxCouponsByDay">
							<span>单天发放上限次数：</span>
							<el-input v-model="form.maxCouponsByDay" placeholder="请输入" maxlength="8" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
							<span>&nbsp;5 ≤ 次数 ≤ 10000000</span>
						</el-form-item>
						<!--            <div v-if="['cash_wx_busi'].includes(form.couponType)">-->
						<!--              <div>-->
						<!--                <el-form-item prop="maxAmountByDay">-->
						<!--                  <span>单天发放上限金额：</span>-->
						<!--                  <span v-if="form.maxAmountByDay">{{ form.maxAmountByDay
            }} 元（0.01 ≤ 金额 ≤ 1000000000）</span>-->
						<!--                  <span v-else>输入单天上限次数，券面额自动计算（单天上限次数 x 券面额）</span>-->
						<!--                </el-form-item>-->
						<!--              </div>-->
						<!--            </div>-->
					</el-form-item>
					<!-- 用户限制 -->
					<el-form-item label="用户限制" class="is-required">
						<el-form-item prop="maxUserAll">
							<span>用户最大领取次数：</span>
							<el-input v-model="form.maxUserAll" placeholder="请输入" maxlength="3" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
						</el-form-item>
					</el-form-item>
				</div>

				<!-- 微信支付券配置  -->
				<div v-if="['cash_wx_pay'].includes(form.couponType)">
					<el-form-item label="发放预算" class="is-required">
						<el-form-item prop="maxCoupons">
							<span>批次总预算次数：&#12288;</span>
							<el-input v-model="form.maxCoupons" placeholder="请输入" maxlength="10" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
							<span>&nbsp;5 ≤ 次数 ≤ 10000000</span>
						</el-form-item>
						<!--            <el-form-item prop="maxAmount">-->
						<!--              <span>批次总预算金额：&#12288;</span>-->
						<!--              <span v-if="form.maxAmount">{{ form.maxAmount }} 元（0.01 ≤ 金额 ≤ 1000000000）</span>-->
						<!--              <span v-else>输入总预算次数，券面额自动计算（总预算次数 x 券面额）</span>-->
						<!--            </el-form-item>-->
						<el-form-item prop="maxCouponsByDay">
							<span>单天发放上限次数：</span>
							<el-input v-model="form.maxCouponsByDay" placeholder="请输入" maxlength="8" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
							<span>&nbsp;5 ≤ 次数 ≤ 10000000</span>
						</el-form-item>

						<!--            <el-form-item prop="maxAmountByDay">-->
						<!--              <span>单天发放上限金额：</span>-->
						<!--              <span v-if="form.maxAmountByDay">{{ form.maxAmountByDay
            }} 元（0.01 ≤ 金额 ≤ 1000000000）</span>-->
						<!--              <span v-else>输入单天上限次数，券面额自动计算（单天上限次数 x 券面额）</span>-->
						<!--            </el-form-item>-->
					</el-form-item>
					<el-form-item label="用户限制" class="is-required">
						<el-form-item prop="maxUserAll">
							<span>用户最大领取次数：</span>
							<el-input v-model="form.maxUserAll" placeholder="请输入" maxlength="3" class="w-200">
								<template slot="append">
									次
								</template>
							</el-input>
						</el-form-item>
					</el-form-item>
					<el-form-item label="自然人限制" prop="naturalPersonLimit" class="is-required">
						<el-select v-model="form.naturalPersonLimit" placeholder="请选择" class="w-400">
							<el-option :value="false" label="不限" />
							<el-option :value="true" label="限制" />
						</el-select>
					</el-form-item>
				</div>

				<!-- KD 商家券配置  -->
				<!-- 发券商户 -->
				<div v-if="['cash', 'discount', 'exchange', 'cash_wx_busi', 'discount_wx_busi'].includes(form.couponType)">
					<!--        <div>-->
					<el-form-item label="发放商户" prop="sendMerchant">
						<el-select v-model="form.sendMerchant" placeholder="请选择" class="w-400">
							<el-option :value="1" label="本商户" />
							<el-option :value="2" label="本商户和已合作的所有商户" />
							<el-option :value="3" label="本商户和指定已合作的部分商户" />
						</el-select>
						<el-form-item style="display: inline-block;min-width: 100px" prop="sendMerchantList">
							<el-button v-if="form.sendMerchant === 3" @click="openDialogMerchantsTree('sendMerchant')">
								<span v-if="form.sendMerchantList.length">
									已选择&nbsp;
									<span class="app-text-color-danger">{{ form.sendMerchantList.length }}</span>
									&nbsp;家商户
								</span>
								<span v-else>选择</span>
							</el-button>
						</el-form-item>
					</el-form-item>
				</div>

				<el-divider content-position="left">核销规则</el-divider>
				<!-- KD 商家券配置  -->
				<div v-if="['cash', 'discount', 'exchange', 'cash_wx_busi', 'discount_wx_busi'].includes(form.couponType)">
					<!-- 核销商户 -->
					<el-form-item label="核销商户" prop="verifyMerchant">
						<el-select v-model="form.verifyMerchant" placeholder="请选择" class="w-400" @change="changeVerifyMerchant">
							<!-- <el-option :value="1" label="本商户下所有店铺" />
							<el-option :value="2" label="本商户和已合作商户的所有店铺" />
							<el-option :value="3" label="指定本商户和已合作商户的部分店铺" /> -->

							<el-option :value="1" label="本商户所有门店" />
							<el-option :value="4" label="本商户部分门店" />
							<!-- 已开通超级会员 -->
							<div v-if="superData.status == 1 && (couponTypeOptions[form.couponType] === '折扣券' || couponTypeOptions[form.couponType] === '满减券')">
								<el-option :value="2" label="本商户与所有合作商户" />
								<el-option :value="3" label="本商户与部分合作商户" />
							</div>
						</el-select>
						<el-form-item style="display: inline-block;min-width: 100px;margin-bottom: 0;" prop="verifyMerchantList">
							<el-button v-if="form.verifyMerchant === 3 || form.verifyMerchant === 4" @click="openDialogMerchantsTree('verifyMerchant')">
								<span v-if="form.verifyMerchantList.length">
									已选择&nbsp;
									<span v-if="form.verifyMerchant != 4" class="app-text-color-danger">{{ form.verifyMerchantList.length }}</span>
									<span v-else class="app-text-color-danger">{{ form.storesNum }}</span>
									&nbsp;家{{ form.verifyMerchant == 4 ? '门店' : '商户' }}
								</span>
								<span v-else>选择</span>
							</el-button>
						</el-form-item>
					</el-form-item>

					<!-- 报名时间 -->
					<!-- <el-form-item v-if="form.verifyMerchant === 2 || form.verifyMerchant === 3" label="报名时间" prop="verifyMerchant">
						<el-date-picker
							v-model="form.verifyMerchantApplyTime"
							:default-time="['00:00:00', '23:59:59']"
							type="datetimerange"
							range-separator="~"
							start-placeholder="开始日期"
							end-placeholder="结束日期"
							value-format="yyyy-MM-dd HH:mm:ss"
						/>
					</el-form-item> -->

					<el-form-item v-if="form.verifyMerchant === 2 || form.verifyMerchant === 3" label="出资方" class="is-required">
						<el-radio v-model="form.capValue" label="1" @change="changeCapValue">
							<span>默认按合作商户类型</span>
							<el-tooltip popper-class="el-tooltip-theme-fresh" placement="top" effect="light">
								<div slot="content">指本商户与合作关系是本商户出资就按照本商户出资，如关系是合作商户出资就按照合作商户出资。</div>
								<i class="el-icon-warning app-text-color-info" />
							</el-tooltip>
						</el-radio>
						<el-radio v-model="form.capValue" label="2" @change="changeCapValue">
							<span>本商户</span>
							<el-tooltip popper-class="el-tooltip-theme-fresh" placement="top" effect="light">
								<div slot="content">指用户使用的优惠将有本商户补贴给合作商户，系统会自动排除掉与本商户未绑定补贴关系的合作商户</div>
								<i class="el-icon-warning app-text-color-info" />
							</el-tooltip>
						</el-radio>
						<el-radio v-model="form.capValue" label="3" @change="changeCapValue">
							<span>合作商户</span>
							<el-tooltip popper-class="el-tooltip-theme-fresh" placement="top" effect="light">
								<div slot="content">当合作商户出资方类型是本商户且不需要合作商户同意，不参与活动出资方为合作商户。</div>
								<i class="el-icon-warning app-text-color-info" />
							</el-tooltip>
						</el-radio>
					</el-form-item>

					<!-- 核销业务 -->
					<el-form-item v-if="form.couponType !== 'exchange'" label="核销业务" class="is-required">
						<el-select v-model="form.verifyBusinessType" placeholder="请选择" class="w-400" @change="changeVerifyBusinessType">
							<el-option :value="1" label="所有的业务场景下可核销" />
							<el-option :value="2" label="指定部分业务场景下可核销" />
						</el-select>
						<el-collapse-transition>
							<div v-if="form.verifyBusinessType === 2" class="nest-card-box" style="margin-top:10px">
								<el-card :body-style="{ padding: '20px 20px 0 20px' }">
									<el-form-item prop="verifyBusiness">
										<el-checkbox-group v-model="form.verifyBusiness">
											<template v-for="item in manageBizCodeOptions">
												<el-checkbox
													v-if="(item.usePay && item.canDiscount) || item.key == 9056"
													:key="item.value"
													:label="String(item.key)"
													:disabled="form.capValue != '' && item.key != 9012"
												>
													{{ item.label }}
												</el-checkbox>
											</template>
										</el-checkbox-group>
									</el-form-item>
								</el-card>
							</div>
						</el-collapse-transition>
					</el-form-item>

					<!-- 微信卡包按钮 -->
					<div v-if="['cash_wx_busi', 'discount_wx_busi'].includes(form.couponType)">
						<el-form-item label="微信卡包按钮" class="is-required">
							<el-select v-model="form.verifyMethod" placeholder="请选择" class="w-400">
								<el-option v-for="(v, k) in verifyMethodOptions" :key="k" :label="v" :value="k" />
							</el-select>
						</el-form-item>
						<el-collapse-transition>
							<div v-if="form.verifyMethod === 'MINI_PROGRAMS'">
								<el-form-item label="小程序APPID" prop="verifyMiniprogramConfig.appId">
									<el-input v-model="form.verifyMiniprogramConfig.appId" placeholder="请输入" style="width:400px" />
								</el-form-item>
								<!-- 小程序路径 -->
								<el-form-item label="小程序路径" prop="verifyMiniprogramConfig.page">
									<el-input v-model.trim="form.verifyMiniprogramConfig.page" placeholder="请输入" style="width:400px" />
								</el-form-item>
							</div>
						</el-collapse-transition>
					</div>
				</div>

				<!-- 微信支付券配置  -->
				<div v-if="['cash_wx_pay'].includes(form.couponType)">
					<!-- 可核销商户号 -->
					<div>
						<el-form-item label="核销商户" prop="verifyMerchants">
							<el-card :body-style="{ 'padding-bottom': '0px' }" class="nest-card-box">
								<el-input v-model="form.verifyMerchants" :autosize="{ minRows: 3, maxRows: 10 }" type="textarea" />
								<div>一行对应一个商户号(可通过Enter换行)，最多添加50个商户号，包含你自己的商户号</div>
							</el-card>
						</el-form-item>
					</div>
					<!--核销商品编码-->
					<el-form-item label="核销商品" prop="availableItems">
						<el-select v-model="form.availableItemsType" placeholder="请选择" class="w-400" prop="limitPayType">
							<el-option :value="1" label="不限" />
							<el-option :value="2" label="指定商品" />
						</el-select>
						<el-collapse-transition>
							<div v-if="form.availableItemsType === 2" class="nest-card-box" style="margin-top:10px">
								<el-table :data="form.availableItems" border stripe size="small" empty-text="暂未配置" style="width: 100%">
									<el-table-column prop="id" label="商品编码" />
									<el-table-column prop="name" label="商品名称" />
									<el-table-column label="操作" width="80">
										<template slot-scope="scope">
											<el-button type="text" @click="delMarketingGoods(scope.$index)">删除</el-button>
										</template>
									</el-table-column>
								</el-table>
								<el-button type="text" icon="el-icon-plus" style="display:block" @click.native.prevent="openDialogMarketingGoodsTable">增加商品</el-button>
							</div>
						</el-collapse-transition>
					</el-form-item>
					<!-- 支付类型 -->
					<el-form-item label="支付类型" class="is-required">
						<el-select v-model="form.wxPayTypeType" placeholder="请选择" class="w-400">
							<el-option :value="1" label="微信支付的全部支付类型都可使用" />
							<el-option :value="2" label="仅部分微信支付类型可使用" />
						</el-select>
						<el-collapse-transition>
							<div v-if="form.wxPayTypeType === 2" class="nest-card-box" style="margin-top:10px">
								<el-card :body-style="{ padding: '20px 20px 0 20px' }">
									<el-form-item prop="wxPayType">
										<el-checkbox-group v-model="form.wxPayType">
											<template v-for="(v, k) in wxPayTypeOptions">
												<el-checkbox :key="k" :label="k">{{ v }}</el-checkbox>
											</template>
										</el-checkbox-group>
									</el-form-item>
								</el-card>
							</div>
						</el-collapse-transition>
					</el-form-item>
					<el-form-item label="支付方式" class="is-required">
						<el-select v-model="form.limitPayType" placeholder="请选择" class="w-400" prop="limitPayType">
							<el-option :value="1" label="所有银行卡和微信零钱都可使用" />
							<el-option :value="2" label="指定银行卡" />
							<el-option :value="3" label="微信零钱" />
						</el-select>
						<el-collapse-transition>
							<div v-if="form.limitPayType === 2" class="nest-card-box" style="margin-top:10px">
								<el-card :body-style="{ padding: '20px 20px 0 20px' }">
									<el-form-item label="指定银行卡" label-width="110px" prop="limitPay">
										<el-cascader v-model="form.limitPay" :options="wxPayBankOptions" filterable clearable style="width:300px" />
										<el-select v-model="form.limitBinType" placeholder="请选择">
											<el-option :value="1" label="不指定卡bin" />
											<el-option :value="2" label="指定卡bin" />
										</el-select>
									</el-form-item>
									<div v-if="form.limitBinType === 2">
										<el-form-item label-width="10px" prop="limitCard.name">
											<span>
												使用
												<span v-if="form.limitPay.length">{{ wxPayBankNameOptions[form.limitPay[form.limitPay.length - 1].split('_')[0]] }}</span>
												&nbsp;
											</span>
											<el-input v-model.trim="form.limitCard.name" maxlength="4" placeholder="卡片名称，4个中文以内" class="w-170" />
											<span>
												&nbsp;
												<span v-if="form.limitPay.length">{{ wxPayBankCardTypeOptions[form.limitPay[form.limitPay.length - 1].split('_')[1]] }}</span>
												支付可享受优惠
											</span>
										</el-form-item>
										<el-form-item label-width="10px" prop="limitCard.bin">
											<el-input v-model="form.limitCard.bin" :autosize="{ minRows: 3, maxRows: 10 }" type="textarea" placeholder="请输入指定的卡bin信息" />
											<div>卡bin号为银行卡前几位数字，最短6位，最长9位，一行一个，最多可输入10个</div>
										</el-form-item>
									</div>
								</el-card>
							</div>
						</el-collapse-transition>
					</el-form-item>
					<!-- 优惠叠加 -->
					<el-form-item label="优惠叠加" prop="combineUse" class="is-required">
						<el-select v-model="form.combineUse" :disabled="form.limitPayType === 2 || form.limitPayType === 3" placeholder="请选择" class="w-400">
							<el-option :value="false" label="不可叠加其他优惠使用" />
							<el-option :value="true" label="支持叠加其他优惠使用" />
						</el-select>
					</el-form-item>
					<!-- 预充值 -->
					<el-form-item label="预充值" prop="noCash" class="is-required">
						<el-select v-model="form.noCash" placeholder="请选择" class="w-400">
							<el-option :value="true" label="设置为免充值优惠券" />
							<el-option :value="false" label="设置为预充值优惠券" />
						</el-select>
					</el-form-item>
				</div>

				<el-form-item label="订单优惠标记" prop="discountTag">
					<el-tag v-for="(v, i) in form.discountTag" :key="'discountTag-' + i" :disable-transitions="false" closable @close="closeDiscountTag(i)">{{ v }}</el-tag>
					<el-input
						ref="discountTagInput"
						v-model.trim="discountTagInputValue"
						class="w-400-h-32"
						size="small"
						placeholder="请输入标记"
						maxlength="10"
						show-word-limit
						@keyup.enter.native="addDiscountTag"
						@blur="addDiscountTag"
					/>
					<div class="tips-text">输入后按Enter回车新增，填写后，需要订单具备该标记才可使用优惠券</div>
				</el-form-item>
			</div>
			<!-- step 1 end -->

			<!-- step 2 start -->
			<div v-show="step === 2">
				<!-- 背景主题 -->
				<el-form-item label="背景主题" prop="theme">
					<div class="flexRSC">
						<el-color-picker v-model="form.theme" :predefine="predefineColors" popper-class="theme-picker-dropdown" />
						<span>&nbsp;{{ form.theme }}</span>
					</div>
				</el-form-item>

				<!-- 品牌名称 -->
				<el-form-item label="品牌名称" prop="brandName">
					<el-input v-model="form.brandName" placeholder="不填写默认使用本商户号名称" maxlength="12" show-word-limit style="width:400px" />
				</el-form-item>

				<!-- LOGO -->
				<div v-if="['cash', 'discount', 'exchange'].includes(form.couponType)">
					<div>
						<el-form-item label="LOGO" prop="logo">
							<div class="upload-container">
								<el-upload
									:action="imageUploadUrl"
									:show-file-list="false"
									:headers="{ 'X-BUSINESS-TOKEN': $store.state.user.token }"
									:before-upload="
										file => {
											return handleImgBefore(file, 1);
										}
									"
									:on-success="
										(res, file) => {
											return handleImgSuccess(res, file, 'logo');
										}
									"
									class="app-uploader-img-plus"
									style="width:120px;height:120px"
								>
									<el-image v-if="form.logo" :src="fileBaseUrl + form.logo" style="width:120px;height:120px" class="img" fit="fill" />
									<i v-else class="el-icon-plus" style="width:120px;height:120px" />
								</el-upload>
								<el-button v-if="form.logo" type="text" size="small" style="margin-left: 10px" class="app-text-color-danger" @click="form.logo = ''">
									删除LOGO
								</el-button>
							</div>
							<div class="tips-text">图片建议尺寸：120*120像素，大小不超过1M，支持JPG、PNG，如果不传默认使用当前券类型的LOGO。</div>
						</el-form-item>

						<el-form-item label="详情封面" prop="detailPage">
							<div class="upload-container">
								<el-upload
									:action="imageUploadUrl"
									:show-file-list="false"
									:headers="{ 'X-BUSINESS-TOKEN': $store.state.user.token }"
									:before-upload="
										file => {
											return handleImgBefore(file, 2);
										}
									"
									:on-success="
										(res, file) => {
											return handleImgSuccess(res, file, 'detailPage');
										}
									"
									class="app-uploader-img-plus"
									style="width:320px;height:200px"
								>
									<el-image v-if="form.detailPage" :src="fileBaseUrl + form.detailPage" style="width:320px;height:200px" class="img" fit="fill" />
									<i v-else class="el-icon-plus" style="width:320px;height:200px" />
								</el-upload>
								<el-button v-if="form.detailPage" type="text" size="small" style="margin-left: 10px" class="app-text-color-danger" @click="form.detailPage = ''">
									删除封面
								</el-button>
							</div>
							<div class="tips-text">图片建议尺寸：850*350像素，大小不超过2M，支持JPG、PNG，如不上传，默认无封面图。</div>
						</el-form-item>
					</div>
				</div>
				<div v-if="['cash_wx_busi', 'discount_wx_busi', 'cash_wx_pay'].includes(form.couponType)">
					<div>
						<el-form-item label="LOGO" prop="logo">
							<div class="upload-container">
								<!--                :action="wxImageUploadUrl+'?mchId='+this.form.wxPayMchid"-->
								<!--:action="wxImageUploadUrl+'?mchid='+form.belongMchid"-->
								<!--:action="wxImageUploadUrl"-->
								<el-upload
									:action="wxImageUploadUrl + '?mchid=' + form.belongMchid"
									:show-file-list="false"
									:headers="{ 'X-BUSINESS-TOKEN': $store.state.user.token }"
									:before-upload="
										file => {
											return handleImgBefore(file, 1, true);
										}
									"
									:on-success="
										(res, file) => {
											return handleImgSuccess(res, file, 'logo');
										}
									"
									class="app-uploader-img-plus"
									style="width:120px;height:120px"
								>
									<el-image v-if="form.logo" :src="form.logo" style="width:120px;height:120px" class="img" referrer-policy="no-referrer" fit="fill" />
									<i v-else class="el-icon-plus" style="width:120px;height:120px" />
								</el-upload>
								<el-button v-if="form.logo" type="text" size="small" style="margin-left: 10px" class="app-text-color-danger" @click="form.logo = ''">
									删除LOGO
								</el-button>
							</div>
							<div class="tips-text">
								<!--                <div>1.上传图片前需填写基础信息中的归属商户号</div>-->
								<div>1.图片建议尺寸：120*120像素，大小不超过1M，支持JPG、PNG，如果不传默认使用当前券类型的LOGO。</div>
							</div>
						</el-form-item>

						<el-form-item label="详情封面" prop="detailPage">
							<div class="upload-container">
								<!--                :action="wxImageUploadUrl+'?mchId='+this.form.wxPayMchid"-->
								<!--:action="wxImageUploadUrl+'?mchid='+form.belongMchid"-->
								<el-upload
									:action="wxImageUploadUrl + '?mchid=' + form.belongMchid"
									:show-file-list="false"
									:headers="{ 'X-BUSINESS-TOKEN': $store.state.user.token }"
									:before-upload="
										file => {
											return handleImgBefore(file, 2, true);
										}
									"
									:on-success="
										(res, file) => {
											return handleImgSuccess(res, file, 'detailPage');
										}
									"
									class="app-uploader-img-plus"
									style="width:320px;height:200px"
								>
									<el-image v-if="form.detailPage" :src="form.detailPage" style="width:320px;height:200px" referrer-policy="no-referrer" class="img" fit="fill" />
									<i v-else class="el-icon-plus" style="width:320px;height:200px" />
								</el-upload>
								<el-button v-if="form.detailPage" type="text" size="small" style="margin-left: 10px" class="app-text-color-danger" @click="form.detailPage = ''">
									删除封面
								</el-button>
							</div>
							<div class="tips-text">
								<!--                <div>1.上传图片前需填写基础信息中的归属商户号</div>-->
								<div>1.图片建议尺寸：850*350像素，大小不超过2M，支持JPG、PNG，如不上传，默认无封面图。</div>
							</div>
						</el-form-item>
					</div>
				</div>

				<!-- 条码显示 -->
				<el-form-item label="条码显示" prop="scanCode" class="is-required">
					<el-select v-model="form.scanCode" placeholder="请选择" class="w-400">
						<el-option :value="3" label="条形码和二维码" />
						<el-option :value="1" label="显示条形码" />
						<el-option :value="2" label="显示二维码" />
					</el-select>
				</el-form-item>

				<!-- 功能按钮 -->
				<div v-if="['cash', 'discount', 'exchange', 'cash_wx_busi', 'discount_wx_busi'].includes(form.couponType)">
					<el-form-item label="功能按钮" prop="functionButton" class="is-required">
						<el-select v-model="form.functionButton" placeholder="请选择" class="w-400">
							<el-option :value="false" label="不显示功能按钮" />
							<el-option :value="true" label="显示功能按钮" />
						</el-select>
					</el-form-item>
					<div v-if="form.functionButton">
						<!-- 按钮文案 -->
						<el-form-item label="按钮文案" prop="functionButtonConfig.word">
							<el-input v-model="form.functionButtonConfig.word" placeholder="请输入" style="width:400px" />
						</el-form-item>

						<!-- 小程序APPID -->
						<el-form-item label="小程序APPID" prop="functionButtonConfig.appId">
							<el-input v-model="form.functionButtonConfig.appId" placeholder="请输入" style="width:400px" />
						</el-form-item>

						<!-- 小程序路径 -->
						<el-form-item label="小程序路径" prop="functionButtonConfig.page">
							<el-input v-model="form.functionButtonConfig.page" placeholder="请输入" style="width:400px" />
						</el-form-item>
					</div>
				</div>

				<!-- 微信卡包按钮 -->
				<div v-if="['cash_wx_busi', 'discount_wx_busi'].includes(form.couponType)">
					<!-- 微信卡包公众号入口 -->
					<el-form-item label="微信卡包公众号入口">
						<el-select v-model="form.customEntrance.appidType" placeholder="请选择" class="w-400">
							<el-option :value="1" label="不配置" />
							<el-option :value="2" label="启用并跳转到本商户已授权的公众号" />
							<el-option :value="3" label="启用并跳转到指定的公众号" />
						</el-select>
					</el-form-item>
					<el-collapse-transition>
						<div v-if="form.customEntrance.appidType === 3">
							<el-form-item label="公众号appid" prop="customEntrance.appid">
								<el-input v-model="form.customEntrance.appid" placeholder="请输入" class="w-400" />
							</el-form-item>
						</div>
					</el-collapse-transition>
					<!-- 微信卡包小程序入口 -->
					<el-form-item label="微信卡包小程序入口" prop="customEntrance.miniProgramsInfo">
						<el-select v-model="form.customEntrance.miniProgramsInfo" placeholder="请选择" class="w-400">
							<el-option :value="false" label="不配置" />
							<el-option :value="true" label="启用并跳转到小程序" />
						</el-select>
					</el-form-item>
					<el-collapse-transition>
						<div v-if="form.customEntrance.miniProgramsInfo">
							<el-form-item label="小程序APPID" prop="customEntrance.miniProgramsAppid">
								<el-input v-model="form.customEntrance.miniProgramsAppid" placeholder="请输入" class="w-400" />
							</el-form-item>
							<el-form-item label="路径" prop="customEntrance.miniProgramsPath">
								<el-input v-model="form.customEntrance.miniProgramsPath" placeholder="请输入" class="w-400" />
							</el-form-item>
							<el-form-item label="入口文案" prop="customEntrance.entranceWords">
								<el-input v-model="form.customEntrance.entranceWords" placeholder="请输入" class="w-400" />
							</el-form-item>
							<el-form-item label="引导文案" prop="customEntrance.guidingWords">
								<el-input v-model="form.customEntrance.guidingWords" placeholder="请输入" class="w-400" />
							</el-form-item>
						</div>
					</el-collapse-transition>
					<!-- 微信卡包营销馆入口 -->
					<el-form-item label="微信卡包营销馆入口">
						<el-select v-model="form.customEntrance.hallType" placeholder="请选择" class="w-400">
							<el-option :value="1" label="不配置" />
							<el-option :value="2" label="启用并跳转到营销馆" />
						</el-select>
					</el-form-item>
					<el-collapse-transition>
						<div v-if="form.customEntrance.hallType === 2">
							<el-form-item label="微信支付营销馆的馆id" prop="customEntrance.hallId">
								<el-input v-model="form.customEntrance.hallId" placeholder="请输入" style="width:400px" />
							</el-form-item>
						</div>
					</el-collapse-transition>
				</div>
			</div>
			<!-- step 2 end -->

			<!-- step 3 start -->
			<div v-if="step === 3 && submitForm">
				<!-- 基础信息 -->
				<!--        <el-form-item label="归属商户号">{{ submitForm.belongMerchant }}</el-form-item>-->
				<el-form-item v-if="submitForm.belongMchid" label="归属商户号">{{ submitForm.belongMchid }}</el-form-item>
				<el-form-item v-if="submitForm.belongMerchantName" label="归属商户名">{{ submitForm.belongMerchantName }}</el-form-item>
				<el-form-item label="券类型">{{ couponTypeOptions[submitForm.couponType] }}</el-form-item>
				<el-form-item label="券名称">{{ submitForm.couponName }}</el-form-item>
				<div v-if="couponTypeGroup.cash.includes(submitForm.couponType)">
					<el-form-item label="券面额">{{ submitForm.denomination / 100 }} 元</el-form-item>
					<el-form-item label="门槛">
						满 {{ submitForm.transactionMinimum / 100 }} 元可使用{{ submitForm.maxUseNum ? '，最多可叠加 ' + submitForm.maxUseNum + ' 张' : '' }}
					</el-form-item>
				</div>
				<div v-if="couponTypeGroup.discount.includes(submitForm.couponType)">
					<el-form-item label="折扣">{{ submitForm.discountPercent / 10 }} 折</el-form-item>
					<el-form-item label="门槛">{{ submitForm.transactionMinimum ? submitForm.transactionMinimum / 100 + ' 元' : '无' }}</el-form-item>
					<el-form-item label="优惠上限">{{ submitForm.discountMaximum ? submitForm.discountMaximum / 100 + ' 元' : '无' }}</el-form-item>
				</div>
				<div v-if="couponTypeGroup.exchange.includes(submitForm.couponType)">
					<el-form-item label="兑换内容">{{ submitForm.exchangeThings }}</el-form-item>
					<el-form-item label="价值">{{ submitForm.denomination ? submitForm.denomination / 100 + ' 元' : '无' }}</el-form-item>
				</div>
				<el-form-item label="可用时间">
					<!-- 总时间 -->
					<div>{{ submitForm.startTime + ' ~ ' + submitForm.endTime }}</div>
					<!-- 时间类型一 -->
					<div v-if="submitForm.availableTime.timeType === 5">有效期内，任意时段可用</div>
					<div v-if="submitForm.availableTime.timeType === 1">生效后 {{ submitForm.availableTime.days }} 天可用</div>
					<div v-if="submitForm.availableTime.timeType === 2">每周指定星期：{{ submitForm.availableTime.availablePeriod | weekNum2WeekStr }}</div>

					<!-- <div v-if="submitForm.availableTime.timeType === 3">每月指定日期：{{ submitForm.availableTime.availablePeriod | dayNum2DayStr }}</div> -->
					<div v-if="submitForm.availableTime.timeType === 3">每月指定日期：{{ submitForm.availableTime.availablePeriod }}</div>
					<div v-if="submitForm.availableTime.timeType === 4">
						范围内指定日期：
						{{
							submitForm.availableTime.dateList
								.split(',')
								.map(function fun(v) {
									return v.replace(':', ' ~ ');
								})
								.join('、')
						}}
					</div>
					<div v-if="submitForm.availableTime.timeType === 2 || submitForm.availableTime.timeType === 3 || submitForm.availableTime.timeType === 4">
						<div v-if="submitForm.availableTime.startMinute1 || submitForm.availableTime.endMinute1">
							{{ submitForm.availableTime.startMinute1 | mm2HHmm }} ~ {{ submitForm.availableTime.endMinute1 | mm2HHmm }}
						</div>
						<div v-if="submitForm.availableTime.startMinute2 || submitForm.availableTime.endMinute2">
							{{ submitForm.availableTime.startMinute2 | mm2HHmm }} ~ {{ submitForm.availableTime.endMinute2 | mm2HHmm }}
						</div>
						<div v-if="submitForm.availableTime.startMinute3 || submitForm.availableTime.endMinute3">
							{{ submitForm.availableTime.startMinute3 | mm2HHmm }} ~ {{ submitForm.availableTime.endMinute3 | mm2HHmm }}
						</div>
					</div>
				</el-form-item>

				<!--v-if="submitForm.availableTime.timeType===1&&['cash','discount','exchange','cash_wx_busi','discount_wx_busi'].includes(submitForm.couponType)"-->
				<el-form-item label="生效时间">
					<div v-if="submitForm.secondDayAvailable">领取后第二天生效</div>
					<div v-else>领取后立即生效</div>
				</el-form-item>
				<el-form-item label="使用说明">
					<ul v-if="submitForm.description">
						<li v-for="(v, i) in submitForm.description.split(/[(\r\n)]+/)" :key="i">{{ v }}</li>
					</ul>
					<div v-else>无</div>
				</el-form-item>

				<!-- 投放规则 -->
				<div v-if="['cash', 'discount', 'exchange'].includes(submitForm.couponType)">
					<el-form-item label="发放预算">
						<div v-if="submitForm.maxCoupons">有效期内可发放总上限为：{{ submitForm.maxCoupons }} 次</div>
						<div v-else>有效期内可发放总上限：无限制</div>
						<div v-if="submitForm.maxCouponsByDay">一个自然日可发放上限为：{{ submitForm.maxCouponsByDay }} 次</div>
						<div v-else>一个自然日可发放上限为：无限制</div>
					</el-form-item>
					<el-form-item label="用户类型">
						<div v-if="submitForm.userGroup === 1">所有人</div>
						<div v-else-if="submitForm.userGroup === 2">仅会员</div>
						<div v-else-if="submitForm.userGroup === 3">
							<template v-for="v in categoryList">
								<span v-if="submitForm.category.split(',').includes(String(v.id))" :key="v.id" class="last-dot">
									<span>{{ v.categoryName }}</span>
									<span class="dot">、</span>
								</span>
							</template>
						</div>
					</el-form-item>
					<el-form-item label="用户限制">
						<div v-if="submitForm.maxUserDay">一个自然日单用户可领取：{{ submitForm.maxUserDay }} 次</div>
						<div v-else>一个自然日单用户可领取：无限制</div>
						<div v-if="submitForm.maxUserWeek">一个自然周单用户可领取：{{ submitForm.maxUserWeek }} 次</div>
						<div v-else>一个自然周单用户可领取：无限制</div>
						<div v-if="submitForm.maxUserMonth">一个自然月单用户可领取：{{ submitForm.maxUserMonth }} 次</div>
						<div v-else>一个自然月单用户可领取：无限制</div>
						<div v-if="submitForm.maxUserAll">有效期内单个用户可领取：{{ submitForm.maxUserAll }} 次</div>
						<div v-else>有效期内单个用户可领取：无限制</div>
					</el-form-item>
					<el-form-item label="发放商户">
						<div v-if="submitForm.sendMerchant === 1">本商户</div>
						<div v-else-if="submitForm.sendMerchant === 2">本商户和已合作的所有商户</div>
						<div v-else-if="submitForm.sendMerchant === 3">
							<template v-for="v in submitForm.sendMerchantList">
								<span :key="v.merchant" class="last-dot">
									<span>{{ v.merchantName }}</span>
									<span class="dot">、</span>
								</span>
							</template>
						</div>
					</el-form-item>
					<el-form-item label="核销商户">
						<!-- <div v-if="submitForm.verifyMerchant === 1">本商户下所有店铺</div>
						<div v-else-if="submitForm.verifyMerchant === 2">本商户和已合作商户的所有店铺</div>
						<div v-else-if="submitForm.verifyMerchant === 3">
							<template v-for="v in submitForm.verifyMerchantList">
								<span :key="v.merchant" class="last-dot">
									<span>{{ v.merchantName }}</span>
									<span class="dot">、</span>
								</span>
							</template>
						</div> -->
						<div v-if="submitForm.verifyMerchant === 1">本商户所有门店</div>
						<div v-if="submitForm.verifyMerchant === 4">本商户部分门店</div>
						<div v-else-if="submitForm.verifyMerchant === 2">本商户与所有合作商户</div>
						<div v-else-if="submitForm.verifyMerchant === 3">
							<template v-for="v in submitForm.verifyMerchantList">
								<span :key="v.merchant" class="last-dot">
									<span>{{ v.merchantName }}</span>
									<span class="dot">、</span>
								</span>
							</template>
						</div>
					</el-form-item>
					<el-form-item label="核销业务">
						<template v-if="submitForm.verifyBusiness">
							<template v-for="v in submitForm.verifyBusiness.split(',')">
								<span :key="v" class="last-dot">
									<span>{{ bizCodeKeyOptions[v] }}</span>
									<span class="dot">、</span>
								</span>
							</template>
						</template>
						<span v-else>所有业务</span>
					</el-form-item>
				</div>

				<div v-if="['cash_wx_busi', 'discount_wx_busi'].includes(submitForm.couponType)">
					<el-form-item label="发放预算">
						<div>
							批次总预算：{{ submitForm.maxCoupons }} 次
							<!--              {{ submitForm.maxAmount ? "，" + submitForm.maxAmount / 100 + ' 元' : "" }}-->
						</div>
						<div>
							单天发放上限：{{ submitForm.maxCouponsByDay }} 次
							<!--              {{ submitForm.maxAmountByDay ? "，" + submitForm.maxAmountByDay / 100 + ' 元' : "" }}-->
						</div>
					</el-form-item>
					<el-form-item label="用户限制">
						<div v-if="submitForm.maxUserAll">用户最大领取次数：{{ submitForm.maxUserAll }} 次</div>
						<div v-else>用户最大领取次数：无限制</div>
					</el-form-item>
					<el-form-item label="发放商户">
						<div v-if="submitForm.sendMerchant === 1">本商户</div>
						<div v-else-if="submitForm.sendMerchant === 2">本商户和已合作的所有商户</div>
						<div v-else-if="submitForm.sendMerchant === 3">
							<template v-for="v in submitForm.sendMerchantList">
								<span :key="v.merchant" class="last-dot">
									<span>{{ v.merchantName }}</span>
									<span class="dot">、</span>
								</span>
							</template>
						</div>
					</el-form-item>
					<!-- KD 商家 -->

					<el-form-item label="核销商户">
						<div v-if="submitForm.verifyMerchant === 1">本商户下所有店铺</div>
						<div v-else-if="submitForm.verifyMerchant === 2">本商户和已合作商户的所有店铺</div>
						<div v-else-if="submitForm.verifyMerchant === 3">
							<template v-for="v in submitForm.verifyMerchantList">
								<span :key="v.merchant" class="last-dot">
									<span>{{ v.merchantName }}</span>
									<span class="dot">、</span>
								</span>
							</template>
						</div>
					</el-form-item>
					<el-form-item label="核销业务">
						<template v-if="submitForm.verifyBusiness">
							<template v-for="v in submitForm.verifyBusiness.split(',')">
								<span :key="v" class="last-dot">
									<span>{{ bizCodeKeyOptions[v] }}</span>
									<span class="dot">、</span>
								</span>
							</template>
						</template>
						<span v-else>所有业务</span>
					</el-form-item>
					<el-form-item label="微信卡包按钮">
						<div>{{ verifyMethodOptions[submitForm.verifyMethod] }}</div>
						<div v-if="submitForm.verifyMethod === 'MINI_PROGRAMS'">
							<div>appid：{{ JSON.parse(submitForm.verifyMiniprogramConfig).appId }}</div>
							<div>路径：{{ JSON.parse(submitForm.verifyMiniprogramConfig).page }}</div>
						</div>
					</el-form-item>
				</div>

				<!-- 代金券 -->
				<div v-if="['cash_wx_pay'].includes(submitForm.couponType)">
					<el-form-item label="发放预算">
						<div>
							批次总预算：{{ submitForm.maxCoupons }} 次
							<!--              {{ submitForm.maxAmount ? "，" + submitForm.maxAmount / 100 + ' 元' : "" }}-->
						</div>
						<div>
							单天发放上限：{{ submitForm.maxCouponsByDay }} 次
							<!--              {{ submitForm.maxAmountByDay ? "，" + submitForm.maxAmountByDay / 100 + ' 元' : "" }}-->
						</div>
					</el-form-item>
					<el-form-item label="用户限制">
						<div v-if="submitForm.maxUserAll">用户最大领取次数：{{ submitForm.maxUserAll }} 次</div>
						<div v-else>用户最大领取次数：无限制</div>
					</el-form-item>
					<el-form-item label="自然人限制">{{ submitForm.naturalPersonLimit ? '限制' : '不限' }}</el-form-item>
					<!--          <el-form-item label="发放商户">-->
					<!--            <div v-if="submitForm.sendMerchant===1">本商户</div>-->
					<!--            <div v-else-if="submitForm.sendMerchant===2">本商户和已合作的所有商户</div>-->
					<!--            <div v-else-if="submitForm.sendMerchant===3">-->
					<!--              <template v-for="v in submitForm.sendMerchantList">-->
					<!--                <span :key="v.merchant" class="last-dot">-->
					<!--                  <span>{{ v.merchantName }}</span>-->
					<!--                  <span class="dot">、</span>-->
					<!--                </span>-->
					<!--              </template>-->
					<!--            </div>-->
					<!--          </el-form-item>-->
					<el-form-item label="核销商户">
						<span>{{ submitForm.verifyMerchants ? submitForm.verifyMerchants.replace(/,/g, '、') : '无' }}</span>
					</el-form-item>
					<el-form-item label="核销商品">
						<div v-if="submitForm.availableItems">
							<div v-for="(v, k) in JSON.parse(submitForm.availableItems)" :key="k">编码：{{ k }}&nbsp;&nbsp;&nbsp;名称：{{ v }}</div>
						</div>
						<div v-else>不限</div>
					</el-form-item>
					<el-form-item label="支付类型">
						<template v-if="submitForm.wxPayType">
							<template v-for="v in submitForm.wxPayType.split(',')">
								<span :key="v" class="last-dot">
									<span>{{ wxPayTypeOptions[v] }}</span>
									<span class="dot">、</span>
								</span>
							</template>
						</template>
						<span v-else>所有类型</span>
					</el-form-item>
					<el-form-item label="支付方式">
						<div v-if="!submitForm.limitPay">所有银行卡和微信零钱都可使用</div>
						<div v-else-if="submitForm.limitPay && submitForm.limitPay === 'CFT'">微信零钱</div>
						<div v-else-if="submitForm.limitPay">
							<div>
								{{ wxPayBankNameOptions[submitForm.limitPay.split('_')[0]] }}
								<span v-if="submitForm.limitCard">{{ JSON.parse(submitForm.limitCard).name }}</span>
								{{ wxPayBankCardTypeOptions[submitForm.limitPay.split('_')[1]] }}
							</div>
							<div v-if="submitForm.limitCard">卡bin：{{ JSON.parse(submitForm.limitCard).bin.join('、') }}</div>
						</div>
					</el-form-item>
					<el-form-item label="优惠叠加">
						<span v-if="submitForm.combineUse">支持叠加其他优惠使用</span>
						<span v-else>不可叠加其他优惠使用</span>
					</el-form-item>
					<el-form-item label="预充值">
						<span v-if="submitForm.noCash">免充值优惠券</span>
						<span v-else>预充值优惠券</span>
					</el-form-item>
				</div>

				<el-form-item label="订单优惠标记">{{ submitForm.discountTag ? submitForm.discountTag.replace(/,/g, '、') : '无' }}</el-form-item>

				<!-- 样式主题 -->
				<el-form-item label="背景主题">
					<div class="flexRSC">
						<span :style="{ backgroundColor: submitForm.theme, height: '22px', width: '22px' }" />
						&nbsp;
						<span>{{ submitForm.theme }}</span>
					</div>
				</el-form-item>
				<el-form-item label="品牌名称">{{ submitForm.brandName }}</el-form-item>
				<div v-if="['cash', 'discount', 'exchange'].includes(submitForm.couponType)">
					<el-form-item label="LOGO">
						<el-image v-if="submitForm.logo" :src="fileBaseUrl + submitForm.logo" style="width:120px;height:120px" fit="fill" />
						<el-image v-else :src="'static/icon/coupon/i-coupon-' + submitForm.couponType + '.png'" style="width:120px;height:120px" fit="fill" />
					</el-form-item>
					<el-form-item label="详情封面">
						<el-image v-if="submitForm.detailPage" :src="fileBaseUrl + submitForm.detailPage" style="width:320px;height:200px" fit="fill" />
						<span v-else>无</span>
					</el-form-item>
				</div>
				<div v-if="['cash_wx_busi', 'discount_wx_busi', 'cash_wx_pay'].includes(submitForm.couponType)">
					<el-form-item label="LOGO">
						<el-image v-if="submitForm.logo" :src="submitForm.logo" style="width:120px;height:120px" referrer-policy="no-referrer" fit="fill" />
						<el-image v-else :src="'static/icon/coupon/i-coupon-' + submitForm.couponType + '.png'" style="width:120px;height:120px" fit="fill" />
					</el-form-item>
					<el-form-item label="详情封面">
						<el-image v-if="submitForm.detailPage" :src="submitForm.detailPage" style="width:320px;height:200px" referrer-policy="no-referrer" fit="fill" />
						<span v-else>无</span>
					</el-form-item>
				</div>
				<el-form-item label="条码显示">
					<div v-if="submitForm.scanCode === 1 || submitForm.scanCode === 3">显示条形码</div>
					<div v-if="submitForm.scanCode === 2 || submitForm.scanCode === 3">显示二维码</div>
					<div />
				</el-form-item>
				<el-form-item v-if="['cash', 'discount', 'exchange', 'cash_wx_busi', 'discount_wx_busi'].includes(submitForm.couponType)" label="功能按钮">
					<div v-if="!submitForm.functionButton">不显示功能按钮</div>
					<div v-else>
						<div>文案：{{ JSON.parse(submitForm.functionButtonConfig).word || '无' }}</div>
						<div>appid：{{ JSON.parse(submitForm.functionButtonConfig).appId || '无' }}</div>
						<div>路径：{{ JSON.parse(submitForm.functionButtonConfig).page || '无' }}</div>
					</div>
				</el-form-item>
				<div v-if="['cash_wx_busi', 'discount_wx_busi'].includes(submitForm.couponType)">
					<el-form-item label="微信卡包公众号入口">
						<div v-if="submitForm.customEntrance.appidType === 1">无</div>
						<div v-else-if="submitForm.customEntrance.appidType === 2">启用并跳转到本商户已授权的公众号</div>
						<div v-else-if="submitForm.customEntrance.appidType === 3">启用并跳转到指定的公众号(appid：{{ submitForm.customEntrance.appid }})</div>
					</el-form-item>
					<el-form-item label="微信卡包小程序入口">
						<div v-if="submitForm.customEntrance.miniProgramsInfo">
							<div>APPID：{{ submitForm.customEntrance.miniProgramsAppid || '无' }}</div>
							<div>路径：{{ submitForm.customEntrance.miniProgramsPath || '无' }}</div>
							<div>入口文案：{{ submitForm.customEntrance.entranceWords || '无' }}</div>
							<div>引导文案：{{ submitForm.customEntrance.guidingWords || '无' }}</div>
						</div>
						<div v-else>无</div>
					</el-form-item>
					<el-form-item label="微信卡包营销馆入口">
						<div v-if="submitForm.customEntrance.hallId">微信支付营销馆的馆id：{{ submitForm.customEntrance.hallId }}</div>
						<div v-else>无</div>
					</el-form-item>
				</div>
			</div>
			<!-- step 3 end -->

			<el-form-item>
				<el-button v-if="1 <= step && step <= 3" round @click="changeStep('sub')">上一步</el-button>
				<el-button v-if="step === 3" type="primary" round @click="submit('save', 'draft')">保存至草稿箱</el-button>
				<el-button v-if="step === 3" type="primary" round @click="submit('save', 'on')">保存并上架</el-button>
				<!-- <el-button v-if="step===3" type="primary" round @click="submit('use')">保存并激活</el-button> -->
				<el-button v-if="step !== 3" round @click="changeStep('add')">下一步</el-button>
			</el-form-item>
		</el-form>
		<!-- 表单 end -->

		<!-- 本商户门店弹框 -->
		<DialogMerchantsTree ref="dialogMerchantsTree" />
		<!--营销商品库-->
		<DialogMarketingGoodsTable ref="dialogMarketingGoodsTable" :has-checked-ids="hasCheckedMarketingGoodsIds" />
	</div>
</template>

<script>
import DialogMerchantsTree from '../components/DialogMerchantsTree';
import DialogMarketingGoodsTable from './components/DialogMarketingGoodsTable';
import CouponValidate from './mixin/CouponValidate';
import { wxPayBankOptions, wxPayBankNameOptions, wxPayBankCardTypeOptions } from '@/assets/json/wxpay-bank';
import { mapGetters } from 'vuex';
import { getAllVipCardList } from '@/api/vip';
import { imgUploadUrl, wxCouponImgUploadUrl } from '@/api/upload';
import { couponDetail, saveKdCoupon, saveAndUp, saveWxPayCoupon, saveWxBusiCoupon } from '../../api/coupon';
import { authMerchants } from '../../api/mch';
import { saveMarketingAccount, getBusinessInfo, getSubsidyAccountBalance, querySuperMemberStatus } from '@/api/business';

export default {
	components: {
		DialogMerchantsTree,
		DialogMarketingGoodsTable
	},
	mixins: [CouponValidate],
	data() {
		const _this = this;
		return {
			// 配置
			couponTypeOptions: {
				cash: '满减券',
				cash_wx_pay: '微信支付代金券',
				cash_wx_busi: '微信商家代金券',
				discount: '折扣券',
				discount_wx_busi: '微信商家折扣券',
				exchange: '兑换券'
			},
			couponTypeGroup: {
				cash: ['cash', 'cash_wx_pay', 'cash_wx_busi'],
				discount: ['discount', 'discount_wx_busi'],
				exchange: ['exchange']
			},
			weekOptions: [
				{ label: '周一', value: 2 },
				{ label: '周二', value: 3 },
				{ label: '周三', value: 4 },
				{ label: '周四', value: 5 },
				{ label: '周五', value: 6 },
				{ label: '周六', value: 7 },
				{ label: '周日', value: 1 }
			],
			wxPayBankOptions: wxPayBankOptions,
			wxPayBankNameOptions: wxPayBankNameOptions,
			wxPayBankCardTypeOptions: wxPayBankCardTypeOptions,
			useRuleOptions: [
				{
					value: 5,
					label: '有效期内，任意时段可用'
				},
				{
					value: 1,
					label: '有效期内，生效后N天可用'
				},
				{
					value: 2,
					label: '有效期内，规则星期可用'
				},
				{
					value: 3,
					label: '有效期内，规则日期可用'
				},
				{
					value: 4,
					label: '有效期内，不规则日期可用'
				}
			],
			verifyMethodOptions: {
				OFF_LINE: '跳转到小程序的券详情页面',
				MINI_PROGRAMS: '跳转到其它小程序',
				PAYMENT_CODE: '跳转到微信付款码'
			},
			wxPayTypeOptions: {
				MICROAPP: '小程序支付',
				APPPAY: 'APP支付',
				PPAY: '免密支付',
				CARD: '刷卡支付',
				FACE: '人脸支付',
				OTHER: '其他支付'
			},
			predefineColors: ['#63B359', '#2C9F67', '#509FC9', '#5885CF', '#9062C0', '#D09A45', '#E4B138', '#EE903C', '#DD6549', '#CC463D'],
			datePickerOptions: {
				disabledDate(time) {
					return _this
						.$momentMini()
						.subtract(1, 'days')
						.isAfter(time);
					// return _this.$momentMini().isAfter(time)
				}
			},
			imageUploadUrl: imgUploadUrl,
			wxImageUploadUrl: wxCouponImgUploadUrl,
			// 状态
			loading: false,
			// 数据
			mode: 'add',
			couponType: 'cash',
			step: 0, // 步骤
			categoryList: [],
			discountTagInputValue: null, // tag值
			couponId: null,
			activeBusinessInfo: null, // 商户Info
			allMchList: [],
			allMchShopList: [],
			hasCheckedMarketingGoodsIds: [],
			form: {
				goodsName: '指定商品可用',
				belongMchid: null,
				// wxPayMchid: null,
				belongMerchant: null, // 归属商户号
				belongMerchantName: null,
				couponType: 'cash', // 券类型
				couponName: null, // 券名称
				denomination: null, // 面额
				transactionMinimum: null, // 使用门槛
				maxUseNum: null, // 叠加限制数量
				discountPercent: null, // 折扣 转88折
				discountMaximum: null, // 最高优惠
				exchangeThings: null, // 兑换内容
				date: null, // 可用日期 no params 需转startTime endTime
				startTime: null, // 开始日期
				endTime: null, // 结束日期
				availableTime: {
					timeType: 5, // 日期类型 1：领券后N天可用，2：规则星期可用，3：规则日期可用，4：不规则日期可用' 5:所有时间
					days: null, // 1：领券后N天可用
					availablePeriodWeek: [], // 2： 有效周 1星期天 no params 需转availablePeriod ,分割string
					availablePeriodDay: [], // 3：有效日 1~31日 no params 需转availablePeriod ,分割string
					availablePeriod: null, // 2： 有效周 3：有效日
					availableDateList: [{ date: null }], // 有效日期  no params 需转dateList yyyy-MM-dd:yyyy-MM-dd,yyyy-MM-dd:yyyy-MM-dd
					dateList: null,
					availableTimeList: [{ time: ['00:00', '23:59'] }], // 有效时间 转start_minute1 end_minute1
					startMinute1: null,
					endMinute1: null,
					startMinute2: null,
					endMinute2: null,
					startMinute3: null,
					endMinute3: null
				},
				secondDayAvailable: false, // 生效时间  转布尔
				description: null, // 使用说明
				maxCouponsChecked: true, // 是否勾选  no params
				maxCoupons: null, // 总预算 次数
				// maxAmountChecked: true, // 是否勾选  no params
				// maxAmount: null, // 总预算 金额
				maxCouponsByDayChecked: true, // 是否勾选  no params
				maxCouponsByDay: null, // 日总预算 数量
				// maxAmountByDayChecked: true, // 是否勾选  no params
				// maxAmountByDay: null, // 日总预算  金额
				userGroup: 1, // 用户类型 // 1所有人 2所有会员 3指定会员
				category: [], // 会员卡Id   需转,分割string
				maxUserDayChecked: true, // 是否勾选  no params
				maxUserDay: null, // 用户日预算
				maxUserWeekChecked: true, // 是否勾选  no params
				maxUserWeek: null, // 用户周预算
				maxUserMonthChecked: true, // 是否勾选  no params
				maxUserMonth: null, // 用户月预算
				maxUserAllChecked: true, // 是否勾选  no params
				maxUserAll: null, // 用户总预算
				naturalPersonLimit: false, // 自然人限制
				sendMerchant: 1, // 发券商户类型 1本商户
				sendMerchantList: [],
				verifyMerchant: 1, // 核销商户类型 1本商户  2本商户和所有合作商户 3本商户与合作商户指定门店  4本商户指定店铺
				verifyMerchantList: [],
				verifyMerchants: null, // 微信支付核销商户 需按行转,分割string
				verifyMerchantApplyTime: [], //报名时间
				capValue: '', //出资方
				availableItemsType: 1, // 核销商品类型  no params 1全部  2指定商品
				availableItems: [], // 核销商品编码  [{codeNo,goodsName}]转对象{codeNo:goodsName}
				verifyBusinessType: 1, // 业务类型 no params  1：所有 2：部分
				verifyBusiness: [], // 业务类型  需转,分割string
				verifyMethod: 'OFF_LINE', // 核销方式
				// 核销方式内容 需转string
				verifyMiniprogramConfig: {
					appId: null, // appid
					page: null // 页面路径
				},
				wxPayTypeType: 1, // 支付类型 no params  1：所有 2：部分
				wxPayType: [], //  支付类型  需转,分割string
				limitPayType: 1, // 银行卡类型  1 :所有 2：指定银行卡  3 :零钱
				limitPay: [], // 支付银行
				limitBinType: 1, // 是否有限制bin
				limitCard: {
					name: null,
					bin: null
				},
				combineUse: false, // 优惠叠加
				noCash: true, // 预充值 true免充，false预充
				discountTag: [], // 优惠标记 需转str
				theme: '#63B359', // 主题色
				brandName: null, // 品牌名称
				logo: null, // LOGO
				detailPage: null, // 详情封面链接
				scanCode: 3, // 条码显示 1：条形码，2：二维码，3：二者
				functionButton: false, // 功能
				// 按钮内容 需转string
				functionButtonConfig: {
					word: null, // 按钮文案
					appId: null, // appid
					page: null // 页面路径
				},
				customEntrance: {
					appidType: 1, // no params 1不配置 2本商户  3其它
					appid: null, //  跳转商户公众号appid，不配置时为null，跳转到已授权公众号时为空字符串
					entranceWords: null, // 入口文案
					guidingWords: null, // 引导文案
					hallType: 1, // no params 1不配置
					hallId: null, // 营销馆id
					miniProgramsAppid: null, // 商家小程序appid
					miniProgramsInfo: false, // 开启小程序入口
					miniProgramsPath: null // 商家小程序路径
				},
				// 核销商户查询类型
				queryType: 0 //0查询所有 1查询本商户 2查询合作商户
			},
			submitForm: null,

			// 超级会员
			superData: null
		};
	},
	computed: {
		...mapGetters(['manageBizCodeOptions', 'bizCodeKeyOptions', 'fileBaseUrl', 'businessInfo'])
	},
	watch: {
		'form.limitPayType'(val) {
			if (val === 3 || val === 2) {
				this.form.combineUse = true;
			}
		}
	},
	created() {
		const referrer = document.getElementById('referrer');
		referrer.setAttribute('content', 'never');
	},
	mounted() {
		const queryParams = this.$route.query;
		if (queryParams.mode === 'add' && queryParams.couponType) {
			this.form.couponType = queryParams.couponType;
			//  判断是否有携带商户参数
			if (queryParams.belongMerchant && queryParams.belongMerchantName) {
				this.activeBusinessInfo = {
					id: queryParams.belongMerchant,
					name: queryParams.belongMerchantName
				};
				this.form.belongMerchant = queryParams.belongMerchant;
				this.form.belongMerchantName = queryParams.belongMerchantName;
			} else {
				this.activeBusinessInfo = this.businessInfo;
				this.form.belongMerchant = this.businessInfo.id;
				this.form.belongMerchantName = this.businessInfo.name;
			}
		} else if (queryParams.mode === 'edit' && queryParams.id) {
			this.mode = queryParams.mode;
			this.couponId = queryParams.id;
		}
		this.fetchData();
		this.getBusinessInfoFun();
	},
	beforeDestroy() {
		const referrer = document.getElementById('referrer');
		referrer.setAttribute('content', 'always');
	},
	methods: {
		/**
		 * 数据组
		 */
		// 初始化数据
		fetchData() {
			this.loading = true;
			if (this.couponId) {
				Promise.all([this.getDetail(), this.getCategoryList()]).finally(() => {
					this.getAuthMerchants();
					this.loading = false;
				});
			} else {
				this.defaultMerchants();
				Promise.all([this.getCategoryList(), this.getAuthMerchants()]).finally(() => {
					this.loading = false;
				});
			}

			this.querySuperMemberStatusFun();
		},

		// 初始化数据
		defaultMerchants() {
			if (['cash', 'discount', 'exchange'].includes(this.form.couponType)) {
				this.form.maxCouponsChecked = false;
				// this.form.maxAmountChecked = false
				this.form.maxCouponsByDayChecked = false;
				// this.form.maxAmountByDayChecked = false
				this.form.maxUserDayChecked = false;
				this.form.maxUserWeekChecked = false;
				this.form.maxUserMonthChecked = false;
				this.form.maxUserAllChecked = false;
			}
			if (['cash'].includes(this.form.couponType)) {
				this.form.maxUseNum = 1;
			}
			if (['cash_wx_pay'].includes(this.form.couponType)) {
				this.form.maxUseNum = 1;
				this.form.maxUserAllChecked = true;
			}
		},

		// 获取合作商户
		getAuthMerchants() {
			return new Promise(resolve => {
				if (this.form.belongMerchant) {
					authMerchants({ belongMerchant: this.form.belongMerchant, queryType: this.form.queryType })
						.then(res => {
							const allMchList = [];
							// const allMchIds = []
							res.data.forEach(v => {
								v.id = 'M-' + v.id;
								// allMchIds.push(v.id)
								allMchList.push({
									id: v.id,
									name: v.name,
									shops: []
								});
							});
							this.allMchList = allMchList;
							this.allMchShopList = res.data;
							this.form.storesMaxNum = res.data[0].shops.length;
							// 判断是编辑 去除失效商户
							// if (this.form.id && this.form.verifyMerchant === 3 && this.form.verifyMerchantList.length) {
							//   for (let i = this.form.verifyMerchantList.length - 1; i >= 0; i--) {
							//     console.log(this.form.verifyMerchantList[i].merchant)
							//     if (!allMchIds.includes(this.form.verifyMerchantList[i].merchant)) {
							//       this.form.verifyMerchantList.splice(i, 1)
							//     }
							//   }
							// }
						})
						.finally(() => {
							resolve();
						});
				} else {
					resolve();
				}
			});
		},

		// 获取会员卡
		getCategoryList() {
			return new Promise(resolve => {
				getAllVipCardList().then(res => {
					this.categoryList = res.data;
					resolve();
				});
			});
		},

		// 获取详情
		getDetail() {
			return new Promise(resolve => {
				couponDetail({ couponId: this.couponId })
					.then(res => {
						// const params = Object.assign(res.data.prototype, res.data)
						// params.customEntrance = params.wxCustomEntrance
						// delete params.wxCustomEntrance
						const params = res.data.prototype;
						params.availableTime = res.data.availableTime;
						params.customEntrance = res.data.wxCustomEntrance;
						params.sendMerchantList = res.data.sendMerchantList;
						params.verifyMerchantList = res.data.verifyMerchantList;

						params.belongMchid = params.wxPayMchid || null;

						// 格式化代金券 专用
						if (this.couponTypeGroup.cash.includes(params.couponType)) {
							params.denomination = params.denomination / 100;
							params.transactionMinimum = params.transactionMinimum / 100;
						}
						// 格式化折扣券 专用
						if (this.couponTypeGroup.discount.includes(params.couponType)) {
							params.discountPercent = params.discountPercent / 10;
							params.transactionMinimum = params.transactionMinimum ? params.transactionMinimum / 100 : 0;
							params.discountMaximum = params.discountMaximum ? params.discountMaximum / 100 : 0;
						}
						// 格式化兑换券 专用
						if (this.couponTypeGroup.exchange.includes(params.couponType)) {
							params.denomination = params.denomination ? params.denomination / 100 : 0;
						}

						// 发放商户
						switch (params.sendMerchant) {
							case 1:
							case 2:
								params.sendMerchantList = [];
								break;
							case 3:
								params.sendMerchantList.forEach(v => {
									v.merchant = 'M-' + v.merchant;
									v.shop = v.shop ? v.shop.split(',') : [];
								});
								break;
						}
						if (['cash', 'discount', 'exchange', 'cash_wx_busi', 'discount_wx_busi'].includes(params.couponType)) {
							// 核销商户
							switch (params.verifyMerchant) {
								case 1:
								case 2:
									params.verifyMerchantList = [];
									break;
								case 3:
									params.verifyMerchantList.forEach(v => {
										v.merchant = 'M-' + v.merchant;
										v.shop = v.shop ? v.shop.split(',') : [];
									});
									break;
								case 4:
									params.verifyMerchantList.forEach(v => {
										v.merchant = 'M-' + v.merchant;
										v.shop = v.shop ? v.shop.split(',') : [];
									});
									break;
							}
							// 核销业务
							if (params.verifyBusiness) {
								params.verifyBusiness = params.verifyBusiness.split(',');
								params.verifyBusinessType = 2;
							} else {
								params.verifyBusinessType = 1;
								params.verifyBusiness = [];
							}
						} else {
							params.verifyBusinessType = 1;
							params.verifyBusiness = [];
						}

						// 格式化微信代金券 专用
						if (['cash_wx_pay'].includes(params.couponType)) {
							// 核券商户号
							params.verifyMerchants = params.verifyMerchants.replace(/,/g, '\r\n');

							if (params.availableItems) {
								params.availableItemsType = 2;
								const marketingGoodsMap = JSON.parse(params.availableItems);
								const marketingGoodsArr = [];
								for (const key in marketingGoodsMap) {
									if (!Object.prototype.hasOwnProperty.call(marketingGoodsMap, key)) continue;
									marketingGoodsArr.push({
										id: key,
										name: marketingGoodsMap[key]
									});
								}
								params.availableItems = marketingGoodsArr;
							} else {
								params.availableItemsType = 1;
								params.availableItems = [];
							}

							if (params.wxPayType) {
								params.wxPayTypeType = 2;
								params.wxPayType = params.wxPayType.split(',');
							} else {
								params.wxPayTypeType = 1;
								params.wxPayType = [];
							}
							// 银行
							if (params.limitPay) {
								if (params.limitPay === 'CFT') {
									params.limitPayType = 3;
									params.limitPay = [];
								} else {
									params.limitPayType = 2;
									params.limitPay = [params.limitPay.split('_')[0], params.limitPay];
								}
							} else {
								params.limitPayType = 1;
								params.limitPay = [];
							}
							if (params.limitCard) {
								params.limitBinType = 2;
								params.limitCard = JSON.parse(params.limitCard);
								params.limitCard.bin = params.limitCard.bin.join('\r\n');
								//     .replace(
								//   /,/g,
								//   '\r\n'
								// )
							} else {
								params.limitBinType = 1;
								params.limitCard = {
									name: null,
									bin: null
								};
							}
						} else {
							params.wxPayTypeType = 1;
							params.wxPayType = [];
							params.limitPayType = 1;
							params.limitPay = [];
							params.limitBinType = 1;
							params.availableItemsType = 1;
							params.availableItems = [];
							params.limitCard = {
								name: null,
								bin: null
							};
						}

						// 格式化商家券 专用
						if (['cash_wx_busi', 'discount_wx_busi'].includes(params.couponType) && params.customEntrance) {
							// if (params.customEntrance.appid == null) {
							//   params.customEntrance.appidType = 1
							// } else if (params.customEntrance.appid === '') {
							//   params.customEntrance.appidType = 2
							// } else {
							//   params.customEntrance.appidType = 3
							// }

							if (params.customEntrance.hallId) {
								params.customEntrance.hallType = 2;
							} else {
								params.customEntrance.hallType = 1;
							}

							if (params.verifyMethod === 'MINI_PROGRAMS') {
								params.verifyMiniprogramConfig = JSON.parse(params.verifyMiniprogramConfig);
							} else {
								params.verifyMiniprogramConfig = {
									appId: null, // appid
									page: null // 页面路径
								};
							}
						} else {
							params.verifyMiniprogramConfig = {
								appId: null,
								page: null
							};
							params.customEntrance = {
								appidType: 1,
								appid: null,
								entranceWords: null,
								guidingWords: null,
								hallType: 1,
								hallId: null,
								miniProgramsAppid: null,
								miniProgramsInfo: false,
								miniProgramsPath: null
							};
						}
						params.date = [params.startTime, params.endTime];
						//报名时间
						params.verifyMerchantApplyTime = [params.signUpStartTime, params.signUpEndTime];
						//出资方
						// params.capValue = params.financingPartyType == 1 ? '2' : params.financingPartyType == 2 ? '3' : '1';
						params.capValue = params.financingParty == 1 ? '2' : params.financingParty == 2 ? '3' : '1';
						//设置请求商户列表的类型
						params.queryType = params.verifyMerchant == 1 ? 1 : params.verifyMerchant == 4 ? 1 : params.verifyMerchant == 2 ? 2 : 0;
						//格式化，核销规则-核销商户（指定本商户和已合作商户的部分门店）
						if (params.capValue) {
							// 格式化出资方
							params.financingPartyType = params.capValue == '1' ? 3 : params.capValue == '2' ? 1 : 2;
							// 格式化报名时间
							params.signUpStartTime = params.verifyMerchantApplyTime[0];
							params.signUpEndTime = params.verifyMerchantApplyTime[1];
							// 选中合作商户，去除无感商户
							if (params.verifyMerchant == 3 && params.capValue == '3') {
								let verifyCooperationList = [];
								let data = params.verifyMerchantList;
								for (let i = 0; i < data.length; i++) {
									let inviteCooperateVo = data[i].inviteCooperateVo;
									// 去除无感商户
									if (inviteCooperateVo && (inviteCooperateVo.needAgree || inviteCooperateVo.financingParty === 2)) {
										let { id, joinAddress, joinBusinessId, joinBusinessName, joinMobilePhone, financingParty, needAgree, relationStatus } = inviteCooperateVo;
										let item = {
											cooperateAddress: joinAddress,
											cooperateId: joinBusinessId,
											cooperateName: joinBusinessName,
											cooperatePhone: joinMobilePhone,
											financingParty: financingParty,
											inviteRecordId: id,
											needAgree: needAgree ? 1 : 0,
											relationStatus: relationStatus
										};
										verifyCooperationList.push(item);
									}
								}
								params.verifyCooperationList = verifyCooperationList;
							} else if (params.verifyMerchant == 4) {
								params.storesNum = params.verifyMerchantList[0].shop.length;
							} else {
								let verifyCooperationList = [];
								let data = params.verifyMerchantList;
								for (let i = 0; i < data.length; i++) {
									let inviteCooperateVo = data[i].inviteCooperateVo;
									if (inviteCooperateVo) {
										let { id, joinAddress, joinBusinessId, joinBusinessName, joinMobilePhone, financingParty, needAgree, relationStatus } = inviteCooperateVo;
										let item = {
											cooperateAddress: joinAddress,
											cooperateId: joinBusinessId,
											cooperateName: joinBusinessName,
											cooperatePhone: joinMobilePhone,
											financingParty: financingParty,
											inviteRecordId: id,
											needAgree: needAgree ? 1 : 0,
											relationStatus: relationStatus
										};
										verifyCooperationList.push(item);
									}
								}
								params.verifyCooperationList = verifyCooperationList;
							}
						}

						// 格式化availableTime 独立数据
						params.availableTime.availablePeriodWeek = [];
						params.availableTime.availablePeriodDay = [];
						params.availableTime.availableDateList = [{ date: null }];
						if (params.availableTime.timeType === 5) {
							params.availableTime.days = null;
						}
						if (params.availableTime.timeType === 1 || params.availableTime.timeType === 5) {
							params.availableTime.availablePeriod = null;
							params.availableTime.dateList = null;
							params.availableTime.startMinute1 = null;
							params.availableTime.startMinute2 = null;
							params.availableTime.startMinute3 = null;
							params.availableTime.endMinute1 = null;
							params.availableTime.endMinute2 = null;
							params.availableTime.endMinute3 = null;
						} else if (params.availableTime.timeType === 2) {
							params.availableTime.availablePeriodWeek = params.availableTime.availablePeriod ? params.availableTime.availablePeriod.split(',') : [];
						} else if (params.availableTime.timeType === 3) {
							params.availableTime.availablePeriodDay = params.availableTime.availablePeriod ? params.availableTime.availablePeriod.split(',') : [];
						} else if (params.availableTime.timeType === 4) {
							const dateListArr = [];
							params.availableTime.dateList.split(',').forEach(v => {
								const date = v.split(':');
								dateListArr.push({ date: [date[0], date[1]] });
							});
							params.availableTime.availableDateList = dateListArr;
						}
						// 格式化availableTime 通用数据
						if (params.availableTime.timeType !== 1 && params.availableTime.timeType !== 5) {
							params.availableTime.days = null;
							const timeListArr = [];
							for (let i = 0; i < 3; i++) {
								if (params.availableTime[`startMinute${i + 1}`] || params.availableTime[`endMinute${i + 1}`]) {
									timeListArr.push({
										time: [
											this.$options.filters.mm2HHmm(params.availableTime[`startMinute${i + 1}`]),
											this.$options.filters.mm2HHmm(params.availableTime[`endMinute${i + 1}`])
										]
									});
								}
							}
							params.availableTime.availableTimeList = timeListArr;
						} else {
							params.availableTime.availableTimeList = [{ time: ['00:00', '23:59'] }];
						}

						// 格式化预算
						params.maxCouponsChecked = true;
						params.maxCouponsByDayChecked = true;
						// params.maxAmountChecked = true
						// params.maxAmountByDayChecked = true
						params.maxUserDayChecked = true;
						params.maxUserWeekChecked = true;
						params.maxUserMonthChecked = true;
						params.maxUserAllChecked = true;
						// params.maxAmount = params.maxAmount ? params.maxAmount / 100 : null
						// params.maxAmountByDay = params.maxAmountByDay
						//   ? params.maxAmountByDay / 100
						//   : null
						if (['cash', 'discount', 'exchange'].includes(params.couponType)) {
							params.maxCouponsChecked = !!params.maxCoupons;
							params.maxCouponsByDayChecked = !!params.maxCouponsByDay;
							// params.maxAmountChecked = !!params.maxAmount
							// params.maxAmountByDayChecked = !!params.maxAmountByDay
							params.maxUserDayChecked = !!params.maxUserDay;
							params.maxUserWeekChecked = !!params.maxUserWeek;
							params.maxUserMonthChecked = !!params.maxUserMonth;
							params.maxUserAllChecked = !!params.maxUserAll;
						}

						// 用户类型
						if (params.category) {
							params.category = params.category ? params.category.split(',') : [];
						}
						// 优惠标签
						params.discountTag = params.discountTag ? params.discountTag.split(',') : [];

						// 功能按钮
						params.functionButtonConfig = params.functionButton
							? JSON.parse(params.functionButtonConfig)
							: {
									word: null,
									appId: null,
									page: null
							  };

						console.log('格式化完成', params);
						this.form = params;
					})
					.catch(() => {})
					.finally(() => {
						resolve();
					});
			});
		},

		/**
		 * 按钮组
		 */
		// 新增日期
		addAvailableDateList() {
			this.form.availableTime.availableDateList.push({ date: '' });
		},

		// 删除日期
		delAvailableDateList(index) {
			this.form.availableTime.availableDateList.splice(index, 1);
			this.$refs.form.validateField('availableDateList');
		},

		// 新增时间
		addAvailableTimeList() {
			this.form.availableTime.availableTimeList.push({ time: '' });
		},

		// 删除时间
		delAvailableTimeList(index) {
			this.form.availableTime.availableTimeList.splice(index, 1);
			this.$refs.form.validateField('availableTime.availableTimeList');
		},

		// 核销规则-核销商户选择
		changeVerifyMerchant(e) {
			this.form.verifyMerchant = e;
			this.form.verifyMerchantList = '';
			this.form.verifyMerchantApplyTime = []; //报名时间
			this.form.capValue = '';
			if (e === 1 || e === 4) {
				this.form.queryType = 1;
			} else if (e === 2) {
				this.form.queryType = 2;
				this.form.capValue = '1';
				this.judgeOpenRelationStatusFun();
			} else {
				this.form.queryType = 0;
				this.form.capValue = '1';
			}
			this.getAuthMerchants();
			this.emptyVerifyBusinessFun();
		},
		// 出资方选择
		changeCapValue(e) {
			//选中本商户 && 未开通
			if (this.form.capValue === '2' && !this.infoData.marketingAccount) {
				this.marketingAccountDialog();
				return;
			}
			// this.form.verifyMerchantList = '';
			// this.emptyVerifyBusinessFun();
			this.judgeOpenRelationStatusFun();
		},
		// 商家信息相关
		getBusinessInfoFun() {
			getBusinessInfo().then(res => {
				if (res.code == 0) {
					this.infoData = res.data;
				}
			});
		},
		// 营销账户弹框
		marketingAccountDialog() {
			this.$prompt(
				'请填写斗拱营销户账户号，如还没开通渠道营销户请点击下方链接开通：<a href="https://dashboard.huifu.com/customers/login" target="_blank" style="color:skyblue">https://dashboard.huifu.com/customers/login</a>',
				'提示',
				{
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					dangerouslyUseHTMLString: true
				}
			)
				.then(({ value }) => {
					this.marketingAccount = value;
					this.saveMarketingAccountFun();
				})
				.catch(() => {});
		},
		// 保存渠道营销户
		saveMarketingAccountFun() {
			let prams = {
				businessId: this.businessInfo.id,
				marketingAccount: this.marketingAccount
			};
			saveMarketingAccount(prams).then(res => {
				// console.log('保存渠道营销户', res);
				if (res.code == 0) {
					this.getSubsidyAccountBalanceFun();
				}
			});
		},
		// 查询补贴账户余额
		getSubsidyAccountBalanceFun() {
			let prams = {
				businessId: this.businessInfo.id
			};
			getSubsidyAccountBalance(prams).then(res => {
				// console.log('查询补贴账户余额', res);
				if (res.code == 0) {
					if (res.data <= 0) {
						this.$confirm('当前补贴账户余额不足不可选择资方-本商户', '提示', {
							confirmButtonText: '立即充值',
							cancelButtonText: '确定',
							type: 'warning'
						})
							.then(() => {
								window.open('https://dashboard.huifu.com/customers/login');
							})
							.catch(() => {});
					}
				}
			});
		},

		// 核销规则-核销业务选择
		changeVerifyBusinessType(e) {
			let that = this;
			setTimeout(function() {
				that.emptyVerifyBusinessFun();
			}, 300);
		},
		// 清空核销规则-核销业务的选项（仅在选中出资方情况下）
		emptyVerifyBusinessFun() {
			if (this.form.verifyMerchant === 2 || this.form.verifyMerchant === 3) {
				this.form.verifyBusiness = [];
			}
		},

		// 打开商户
		openDialogMerchantsTree(mode) {
			let checkedIds = [];
			let treeData = [];
			let verifyMerchant = this.form.verifyMerchant;
			if (mode === 'sendMerchant') {
				treeData = this.allMchList;
				this.form.sendMerchantList.forEach(v => {
					checkedIds.push(v.merchant);
				});
			} else if (mode === 'verifyMerchant') {
				treeData = this.allMchShopList;
				this.form.verifyMerchantList = this.form.verifyMerchantList.length > 0 ? this.form.verifyMerchantList : [];
				this.form.verifyMerchantList.forEach(v => {
					checkedIds = checkedIds.concat(v.shop);
				});
			}
			this.$refs.dialogMerchantsTree.open({ treeData, checkedIds, verifyMerchant }).then(res => {
				if (mode === 'sendMerchant') {
					this.$refs.form.clearValidate(['sendMerchantList']);
					this.form.sendMerchantList = res;
				} else if (mode === 'verifyMerchant') {
					this.$refs.form.clearValidate(['verifyMerchantList']);
					this.form.verifyMerchantList = res;
					this.restoreVerifyMerchantListFun();
					this.judgeOpenRelationStatusFun();
				}
			});
		},
		// 选择中,如果inviteCooperateVo为null,则恢复选择"本商户下所有店铺"
		// 注意:inviteCooperateVo != null ,才是合作商户
		restoreVerifyMerchantListFun() {
			// 如果"本商户部分门店"：
			// 选中个别门店,则展示 x 家门店,
			// 全选中,则自动 this.form.verifyMerchant = 1
			let arr = [];
			let data = this.form.verifyMerchantList;
			let shopLen = data[0].shop.length;
			if (this.form.verifyMerchant == 4 && shopLen < this.form.storesMaxNum) {
				if (shopLen > 0) {
					this.form.storesNum = data[0].shop.length;
				}
			} else {
				data.forEach(el => {
					if (el.inviteCooperateVo) {
						arr.push(el);
					}
				});
				if (arr.length <= 0) {
					this.form.verifyMerchant = 1;
					this.form.capValue == '';
				}
			}
		},

		// 当核心商户选择本商户或者全部合作商户，选择了出资方“本商户”默认把非补贴关系商户排除
		judgeOpenRelationStatusFun() {
			if (this.form.verifyMerchant == 3 && this.form.capValue == '2') {
				let verifyCooperationList = [];
				let data = this.form.verifyMerchantList;
				for (let i = 0; i < data.length; i++) {
					let inviteCooperateVo = data[i].inviteCooperateVo;
					// 去除补贴关系商户
					if (!inviteCooperateVo || inviteCooperateVo.openRelationStatus) {
						verifyCooperationList.push(data[i]);
					}
				}
				this.form.verifyMerchantList = verifyCooperationList;
				if (verifyCooperationList.length < 1) {
					this.form.verifyMerchantList = '';
					this.form.verifyMerchant = 1;
					this.form.capValue == '';
					this.$message({
						message: '商圈券，邀请的合作商户列表不能为空',
						type: 'warning'
					});
				}
			}
		},

		// 超级会员插件状态
		querySuperMemberStatusFun() {
			querySuperMemberStatus().then(res => {
				this.superData = res.data;
			});
		},

		// 增加营销商品
		openDialogMarketingGoodsTable() {
			this.hasCheckedMarketingGoodsIds = [];
			this.form.availableItems.forEach(v => {
				this.hasCheckedMarketingGoodsIds.push(v.id);
			});
			this.$nextTick(() => {
				this.$refs.dialogMarketingGoodsTable.open().then(res => {
					this.$refs.form.clearValidate(['availableItems']);
					this.form.availableItems = this.form.availableItems.concat(res);
				});
			});
		},

		// 删除营销商品
		delMarketingGoods(index) {
			this.form.availableItems.splice(index, 1);
		},

		// 关闭优惠标记
		closeDiscountTag(index) {
			this.form.discountTag.splice(index, 1);
		},

		// 新增优惠标签
		addDiscountTag() {
			const inputValue = this.discountTagInputValue;
			if (inputValue) {
				this.form.discountTag.push(inputValue);
				this.form.discountTag = [...new Set(this.form.discountTag)];
				this.discountTagInputValue = '';
			}
		},

		// 上传图片之前
		handleImgBefore(file, size, needMchId = false) {
			if (needMchId && !this.form.belongMchid) {
				this.$message.error('请补充基础信息中归属商户号后进行上传');
				return false;
			}
			return this.beforeUploadImg(file, this, 0, 0, size);
		},

		// 上传图片成功
		handleImgSuccess(res, file, type) {
			console.log(res, type);
			if (['cash_wx_busi', 'discount_wx_busi', 'cash_wx_pay'].includes(this.form.couponType)) {
				if (res.code === 0) {
					this.form[type] = res.data;
					this.$refs.form.clearValidate([type]);
				} else {
					this.$message.error(res.msg);
				}
			} else {
				if (res.code === 0) {
					this.form[type] = res.data.path;
					this.$refs.form.clearValidate([type]);
				} else {
					this.$message.error(res.msg);
				}
			}
		},

		// 修改步骤
		changeStep(mode = 'add') {
			if (mode === 'add') {
				if (this.step === 2) {
					this.submit(mode);
					return;
				}
				this.step += 1;
			} else {
				this.step -= 1;
			}
		},

		// 保存
		submit: function(mode = 'save', saveType) {
			// 判断是否是查看详细
			this.$refs.form.validate((valid, error) => {
				if (!valid) {
					console.log('valid false', error);
					const errorArr = Object.keys(error);
					const propObj = {
						0: [
							// 'wxPayMchid',
							'belongMchid',
							'stockName',
							'couponName',
							'denomination',
							'transactionMinimum',
							'maxUseNum',
							'discountPercent',
							'discountMaximum',
							'exchangeThings',
							'date',
							'availableTime.days',
							'availableTime.availablePeriodWeek',
							'availableTime.availablePeriodDay',
							'availableTime.availableDateList',
							'availableTime.availableTimeList',
							'description'
						],
						1: [
							'maxCoupons',
							'maxCouponsByDay',
							'category',
							'maxUserDay',
							'maxUserWeek',
							'maxUserMonth',
							'maxUserAll',
							'sendMerchant',
							'sendMerchantList',
							'verifyMerchant',
							'verifyMerchantList',
							'verifyBusiness',
							'verifyMethod',
							'verifyMiniprogramConfig.appId',
							'verifyMerchants',
							'availableItems',
							'wxPayType',
							'limitPay',
							'limitCard.name',
							'limitCard.bin'
						],
						2: [
							'theme',
							'functionButtonConfig.word',
							'functionButtonConfig.appId',
							'functionButtonConfig.page',
							'customEntrance.appid',
							'customEntrance.miniProgramsAppid',
							'customEntrance.miniProgramsPath',
							'customEntrance.entranceWords',
							'customEntrance.hallId'
						]
					};

					let errStep = [];
					errorArr.forEach(v => {
						for (const key in propObj) {
							if (propObj[key].includes(v)) {
								errStep.push(key);
							}
						}
					});
					errStep = [...new Set(errStep)];
					if (errStep.includes('0')) {
						this.step = 0;
					} else if (errStep.includes('1')) {
						this.step = 1;
					} else if (errStep.includes('2')) {
						this.step = 2;
					}
					this.$message.warning('请补充完整信息');
				} else {
					console.log('valid true', this.form);
					// 提交表单 处理相关数据
					const params = JSON.parse(JSON.stringify(this.form));
					// 格式化代金券 专用
					if (this.couponTypeGroup.cash.includes(params.couponType)) {
						params.denomination = this.$math.mul(params.denomination, 100, 0);
						params.transactionMinimum = this.$math.mul(params.transactionMinimum, 100, 0);
					}
					// 格式化折扣券 专用
					if (this.couponTypeGroup.discount.includes(params.couponType)) {
						params.discountPercent = this.$math.mul(params.discountPercent, 10, 0);
						params.transactionMinimum = params.transactionMinimum ? this.$math.mul(params.transactionMinimum, 100, 0) : 0;
						params.discountMaximum = params.discountMaximum ? this.$math.mul(params.discountMaximum, 100, 0) : 0;
					}
					// 格式化兑换券 专用
					if (this.couponTypeGroup.exchange.includes(params.couponType)) {
						params.denomination = params.denomination ? this.$math.mul(params.denomination, 100, 0) : 0;
					}

					// 格式化微信代金券 专用
					if (['cash_wx_pay'].includes(params.couponType)) {
						// 核券商户号
						params.verifyMerchants = params.verifyMerchants
							.trim()
							.replace(/\r\n|\n|\r/g, ',')
							.replace(/,+/g, ',');
						if (params.availableItemsType === 2 && params.availableItems.length > 0) {
							const availableItemsMap = {};
							params.availableItems.forEach(v => {
								availableItemsMap[v.id] = v.name;
							});
							params.availableItems = JSON.stringify(availableItemsMap);
						} else {
							params.availableItems = null;
						}
						// 支付类型
						params.wxPayType = params.wxPayTypeType === 1 ? '' : params.wxPayType.join();
						delete params.wxPayTypeType;
						//  使用支付银行卡
						switch (params.limitPayType) {
							case 1:
								params.limitPay = null;
								params.limitCard = null;
								break;
							case 2:
								params.limitPay = params.limitPay[params.limitPay.length - 1];
								if (params.limitBinType === 2) {
									params.limitCard.bin = params.limitCard.bin
										.trim()
										.replace(/\r\n|\n|\r/g, ',')
										.replace(/,+/g, ',')
										.replace(/\s*/g, '')
										.split(',');
									params.limitCard = JSON.stringify(params.limitCard);
								} else {
									params.limitCard = null;
								}
								break;
							case 3:
								params.limitPay = 'CFT';
								params.limitCard = null;
								break;
						}
					} else {
						params.wxPayType = '';
						params.limitPay = null;
						params.limitCard = null;
					}
					delete params.availableItemsType;
					delete params.limitPayType;
					delete params.limitBinType;

					// 格式化商家券 专用
					if (['cash_wx_busi', 'discount_wx_busi'].includes(params.couponType)) {
						if (params.customEntrance.appidType === 1 || params.customEntrance.appidType === 2) {
							params.customEntrance.appid = null;
						}
						if (params.customEntrance.hallType === 1) {
							params.customEntrance.hallId = '';
						}
						if (!params.customEntrance.miniProgramsInfo) {
							params.customEntrance.miniProgramsAppid = '';
							params.customEntrance.entranceWords = '';
							params.customEntrance.miniProgramsPath = '';
							params.customEntrance.guidingWords = '';
						}
						if (params.verifyMethod === 'MINI_PROGRAMS') {
							params.verifyMiniprogramConfig = JSON.stringify(params.verifyMiniprogramConfig);
						} else {
							params.verifyMiniprogramConfig = '';
						}
					} else {
						params.verifyMiniprogramConfig = '';
					}
					delete params.customEntrance.hallType;

					// 格式化商家券 KD券 专用
					// 发放商户
					switch (params.sendMerchant) {
						case 1:
						case 2:
							params.sendMerchantList = [];
							break;
						case 3:
							params.sendMerchantList.forEach(v => {
								v.merchant = String(v.merchant).replace('M-', '');
								v.shop = v.shop.join();
							});
							break;
					}
					if (['cash', 'discount', 'exchange', 'cash_wx_busi', 'discount_wx_busi'].includes(params.couponType)) {
						// 核销商户
						switch (params.verifyMerchant) {
							case 1:
							case 2:
								params.verifyMerchantList = [];
								break;
							case 3:
								params.verifyMerchantList.forEach(v => {
									v.merchant = String(v.merchant).replace('M-', '');
									v.shop = v.shop.join();
								});
								break;
							case 4:
								params.verifyMerchantList.forEach(v => {
									v.merchant = String(v.merchant).replace('M-', '');
									v.shop = v.shop.join();
								});
								break;
						}
						// 核销业务
						params.verifyBusiness = params.verifyBusinessType === 1 ? '' : params.verifyBusiness.join();
					}

					// 格式化date
					params.startTime = params.date[0];
					params.endTime = params.date[1];
					delete params.date;
					// 格式化availableTime 独立数据
					if (params.availableTime.timeType === 1) {
						params.availableTime.availablePeriod = '';
						params.availableTime.dateList = '';
						params.availableTime.startMinute1 = '';
						params.availableTime.startMinute2 = '';
						params.availableTime.startMinute3 = '';
						params.availableTime.endMinute1 = '';
						params.availableTime.endMinute2 = '';
						params.availableTime.endMinute3 = '';
					} else if (params.availableTime.timeType === 2) {
						params.availableTime.availablePeriod = params.availableTime.availablePeriodWeek.join();
					} else if (params.availableTime.timeType === 3) {
						params.availableTime.availablePeriod = params.availableTime.availablePeriodDay.join();
					} else if (params.availableTime.timeType === 4) {
						const dateListArr = [];
						params.availableTime.availableDateList.forEach(v => {
							if (v && v.date.length === 2) {
								dateListArr.push(v.date[0] + ':' + v.date[1]);
							}
						});
						params.availableTime.dateList = dateListArr.join();
					}
					// 格式化availableTime 通用数据
					if (params.availableTime.timeType !== 1) {
						params.availableTime.days = '';
						params.availableTime.availableTimeList.forEach((v, i) => {
							if (v && v.time.length === 2) {
								params.availableTime[`startMinute${i + 1}`] = this.$momentMini.duration(v.time[0]).asMinutes();
								params.availableTime[`endMinute${i + 1}`] = this.$momentMini.duration(v.time[1]).asMinutes();
							}
						});
					}
					delete params.availableTime.availablePeriodWeek;
					delete params.availableTime.availablePeriodDay;
					delete params.availableTime.availableDateList;
					delete params.availableTime.availableTimeList;

					// 格式化预算
					if (!params.maxCouponsChecked) params.maxCoupons = 0;
					// if (params.maxAmountChecked && params.maxAmount) {
					//   params.maxAmount = this.$math.mul(params.maxAmount, 100, 0)
					// }
					if (!params.maxCouponsByDayChecked) params.maxCouponsByDay = 0;
					// if (!params.maxAmountByDayChecked) {
					//   params.maxAmountByDay = 0
					// } else if (params.maxAmountByDay) {
					//   params.maxAmountByDay = this.$math.mul(
					//     params.maxAmountByDay,
					//     100,
					//     0
					//   )
					// }
					if (!params.maxUserDayChecked) params.maxUserDay = 0;
					if (!params.maxUserWeekChecked) params.maxUserWeek = 0;
					if (!params.maxUserMonthChecked) params.maxUserMonth = 0;
					if (!params.maxUserAllChecked) params.maxUserAll = 0;
					delete params.maxCouponsChecked;
					delete params.maxCouponsByDayChecked;
					// delete params.maxAmountChecked
					// delete params.maxAmountByDayChecked
					delete params.maxUserDayChecked;
					delete params.maxUserWeekChecked;
					delete params.maxUserMonthChecked;
					delete params.maxUserAllChecked;

					// 用户类型
					if (params.userGroup === 3) {
						params.category = params.category.join();
					} else {
						params.category = '';
					}

					// 优惠标签
					params.discountTag = params.discountTag.join();

					// 品牌名称 归属商户
					params.brandName = params.brandName || this.activeBusinessInfo.name;

					// 功能按钮
					params.functionButtonConfig = params.functionButton ? JSON.stringify(params.functionButtonConfig) : '';

					//格式化，核销规则-核销商户（指定本商户和已合作商户的部分门店）
					if (params.capValue) {
						// 格式化出资方
						params.financingPartyType = params.capValue == '1' ? 3 : params.capValue == '2' ? 1 : 2;
						// 格式化报名时间
						params.signUpStartTime = params.verifyMerchantApplyTime[0];
						params.signUpEndTime = params.verifyMerchantApplyTime[1];
						// 选中合作商户，去除无感商户
						if (this.form.verifyMerchant == 3 && this.form.capValue == '3') {
							let verifyCooperationList = [];
							let data = this.form.verifyMerchantList;
							for (let i = 0; i < data.length; i++) {
								let inviteCooperateVo = data[i].inviteCooperateVo;
								// 去除无感商户
								if (inviteCooperateVo && (inviteCooperateVo.needAgree || inviteCooperateVo.financingParty === 2)) {
									let { id, joinAddress, joinBusinessId, joinBusinessName, joinMobilePhone, financingParty, needAgree, relationStatus } = inviteCooperateVo;
									let item = {
										cooperateAddress: joinAddress,
										cooperateId: joinBusinessId,
										cooperateName: joinBusinessName,
										cooperatePhone: joinMobilePhone,
										financingParty: financingParty,
										inviteRecordId: id,
										needAgree: needAgree ? 1 : 0,
										relationStatus: relationStatus
									};
									verifyCooperationList.push(item);
								}
							}
							params.verifyCooperationList = verifyCooperationList;
						} else {
							let verifyCooperationList = [];
							let data = this.form.verifyMerchantList;
							for (let i = 0; i < data.length; i++) {
								let inviteCooperateVo = data[i].inviteCooperateVo;
								if (inviteCooperateVo) {
									let { id, joinAddress, joinBusinessId, joinBusinessName, joinMobilePhone, financingParty, needAgree, relationStatus } = inviteCooperateVo;
									let item = {
										cooperateAddress: joinAddress,
										cooperateId: joinBusinessId,
										cooperateName: joinBusinessName,
										cooperatePhone: joinMobilePhone,
										financingParty: financingParty,
										inviteRecordId: id,
										needAgree: needAgree ? 1 : 0,
										relationStatus: relationStatus
									};
									verifyCooperationList.push(item);
								}
							}
							params.verifyCooperationList = verifyCooperationList;
						}
					}

					// 缓存需提交的表单数据
					this.submitForm = params;
					console.log('提交的表单数据', params);
					if (mode === 'add') {
						this.step += 1;
					} else {
						// 判断不同类型不同创建接口
						if (['cash', 'discount', 'exchange'].includes(params.couponType)) {
							// 格式化verifyMerchantList
							if (params.capValue) {
								this.resetVerifyMerchantListFun(params,saveType);
								return;
							}
							console.log('saveType 1',saveType)
							this.saveKd(params, saveType);
						}
						if (['cash_wx_busi', 'discount_wx_busi'].includes(params.couponType)) {
							this.saveWxBusi(params);
						}
						if (['cash_wx_pay'].includes(params.couponType)) {
							this.saveWxPay(params);
						}
					}
				}
			});
		},

		// 重置verifyMerchantList
		resetVerifyMerchantListFun(params,saveType) {
			authMerchants({ belongMerchant: this.form.belongMerchant, queryType: this.form.queryType }).then(res => {
				let data = res.data[0];
				let merchantList = [
					{
						shops: [],
						merchant: data.id,
						merchantName: data.name,
						shop: []
					}
				];
				for (let i = 0; i < data.shops.length; i++) {
					let item = {
						id: data.shops[i].id,
						name: data.shops[i].name,
						phone: data.shops[i].phone,
						longitude: data.shops[i].longitude,
						latitude: data.shops[i].latitude
					};
					merchantList[0].shops.push(item);
					merchantList[0].shop.push(data.shops[i].id);
					if (i == data.shops.length - 1) {
						merchantList[0].shop = merchantList[0].shop.toString();
					}
				}
				params.verifyMerchantList = merchantList;
				this.saveKd(params,saveType);
			});
		},

		// kd券
		saveKd(params, saveType) {
			this.loading = true;
			if (saveType === 'draft') {
				saveKdCoupon(params)
					.then(() => {
						this.$notify({
							title: '成功',
							message: '保存成功',
							type: 'success',
							duration: 2000,
							offset: 40
						});
						this.$router.push({
							name: 'CardsAndOfferManageCoupon',
							params: { saveType }
						});
					})
					.catch(() => {})
					.finally(() => {
						this.loading = false;
					});
			} else {
				saveAndUp(params)
					.then(() => {
						this.$notify({
							title: '成功',
							message: '保存成功',
							type: 'success',
							duration: 2000,
							offset: 40
						});
						this.$router.push({
							name: 'CardsAndOfferManageCoupon',
							params: { saveType }
						});
					})
					.catch(() => {})
					.finally(() => {
						this.loading = false;
					});
			}
		},

		// 商家券
		saveWxBusi(params) {
			this.loading = true;
			saveWxBusiCoupon(params)
				.then(() => {
					this.$notify({
						title: '成功',
						message: '保存成功',
						type: 'success',
						duration: 2000,
						offset: 40
					});
					this.back();
				})
				.catch(() => {})
				.finally(() => {
					this.loading = false;
				});
		},

		// 支付
		saveWxPay(params) {
			this.loading = true;
			saveWxPayCoupon(params)
				.then(() => {
					this.$notify({
						title: '成功',
						message: '保存成功',
						type: 'success',
						duration: 2000,
						offset: 40
					});
					this.back();
				})
				.catch(() => {})
				.finally(() => {
					this.loading = false;
				});
		},

		// 返回
		back() {
			this.$router.go(-1);
		}

		/**
		 * 状态组
		 */

		/**
		 * 方法组
		 */
	}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
/* 通用类 */
/* 布局 */
.w-170 {
	width: 170px;
}

.w-200 {
	width: 200px;
}

.w-300 {
	width: 300px;
}

.w-400 {
	width: 400px;
}

.w-400-h-32 {
	width: 400px;
	height: 32px;
}

.last-dot:last-child .dot {
	display: none;
}

.el-tag {
	margin-right: 10px;
	margin-bottom: 10px;
}

/* 步骤 */
.step-container {
	max-width: 800px;
	margin: 10px 0 30px;
	padding-left: 100px;
}

/* 嵌套内盒子 */
.nest-card-box {
	width: 80%;
	min-width: 700px;
	max-width: 1000px;

	.el-card {
		margin-bottom: 10px;
	}
}

/* 提示文本 */
.tips-text {
	color: $light-font-color;
	line-height: 1.7;
}

/* 月日期盒子 */
.day-box {
	width: 380px;
	display: flex;
	flex-wrap: wrap;

	::v-deep {
		.el-checkbox-button .el-checkbox-button__inner {
			width: 50px;
			margin: 2px 4px 2px 0;
			border: 1px solid #dcdfe6;
			border-radius: 0;
		}
	}
}

/* 主题 */
.theme-picker-dropdown {
	::v-deep {
		.el-color-dropdown__main-wrapper {
			display: none;
		}
	}
}

/* 上传图片 */
.upload-container {
	display: flex;

	.el-icon-plus {
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 36px;
		color: #8c939d;
	}

	.img {
		display: block;
	}
}
</style>

<style rel="stylesheet/scss" lang="scss">
/* 主题 */
.theme-picker-dropdown {
	::v-deep .el-color-dropdown__main-wrapper,
	.el-color-dropdown__value {
		display: none;
	}
}
</style>
